Bash getting integer expression expected

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have following script to check disk usage
#!/bin/bash
# set alert level 90% is default
ALERT=10
OIFS=$IFS
IFS=','
storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk ' print $5 " " $1 ')
for output in $storage ;
do
echo "---------------@@@@@@@@@ output started @@@@@@@@@@@@@@@@-----------"
echo $output
echo "---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------"
usep=$(echo $output | awk ' print $1' | cut -d'%' -f1 )
echo "---------------###### useo started ######-----------"
echo $usep
echo "---------------###### usep end ######-----------"
if [ $usep -ge $ALERT ]; then
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done
But when i am running this code i am getting the integer expression expected error at if conditional statement, Here is the output of this script
97% /dev/sda1
1% udev
0% none
2% none
---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------
---------------###### useo started ######-----------
97
1
0
2
---------------###### usep end ######-----------
./fordiskfor.sh: line 24: [: 97
1
0
2: integer expression expected
bash shell shell-script
add a comment |
up vote
0
down vote
favorite
I have following script to check disk usage
#!/bin/bash
# set alert level 90% is default
ALERT=10
OIFS=$IFS
IFS=','
storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk ' print $5 " " $1 ')
for output in $storage ;
do
echo "---------------@@@@@@@@@ output started @@@@@@@@@@@@@@@@-----------"
echo $output
echo "---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------"
usep=$(echo $output | awk ' print $1' | cut -d'%' -f1 )
echo "---------------###### useo started ######-----------"
echo $usep
echo "---------------###### usep end ######-----------"
if [ $usep -ge $ALERT ]; then
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done
But when i am running this code i am getting the integer expression expected error at if conditional statement, Here is the output of this script
97% /dev/sda1
1% udev
0% none
2% none
---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------
---------------###### useo started ######-----------
97
1
0
2
---------------###### usep end ######-----------
./fordiskfor.sh: line 24: [: 97
1
0
2: integer expression expected
bash shell shell-script
$usepcontains no integer.
– Cyrus
Nov 14 '14 at 6:12
what should i do
– pushpendra chauhan
Nov 14 '14 at 6:19
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have following script to check disk usage
#!/bin/bash
# set alert level 90% is default
ALERT=10
OIFS=$IFS
IFS=','
storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk ' print $5 " " $1 ')
for output in $storage ;
do
echo "---------------@@@@@@@@@ output started @@@@@@@@@@@@@@@@-----------"
echo $output
echo "---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------"
usep=$(echo $output | awk ' print $1' | cut -d'%' -f1 )
echo "---------------###### useo started ######-----------"
echo $usep
echo "---------------###### usep end ######-----------"
if [ $usep -ge $ALERT ]; then
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done
But when i am running this code i am getting the integer expression expected error at if conditional statement, Here is the output of this script
97% /dev/sda1
1% udev
0% none
2% none
---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------
---------------###### useo started ######-----------
97
1
0
2
---------------###### usep end ######-----------
./fordiskfor.sh: line 24: [: 97
1
0
2: integer expression expected
bash shell shell-script
I have following script to check disk usage
#!/bin/bash
# set alert level 90% is default
ALERT=10
OIFS=$IFS
IFS=','
storage=$(df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk ' print $5 " " $1 ')
for output in $storage ;
do
echo "---------------@@@@@@@@@ output started @@@@@@@@@@@@@@@@-----------"
echo $output
echo "---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------"
usep=$(echo $output | awk ' print $1' | cut -d'%' -f1 )
echo "---------------###### useo started ######-----------"
echo $usep
echo "---------------###### usep end ######-----------"
if [ $usep -ge $ALERT ]; then
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done
But when i am running this code i am getting the integer expression expected error at if conditional statement, Here is the output of this script
97% /dev/sda1
1% udev
0% none
2% none
---------------@@@@@@@@@ output end @@@@@@@@@@@@@@@@-----------
---------------###### useo started ######-----------
97
1
0
2
---------------###### usep end ######-----------
./fordiskfor.sh: line 24: [: 97
1
0
2: integer expression expected
bash shell shell-script
bash shell shell-script
edited Nov 25 at 14:42
Rui F Ribeiro
38.3k1476127
38.3k1476127
asked Nov 14 '14 at 6:07
pushpendra chauhan
101
101
$usepcontains no integer.
– Cyrus
Nov 14 '14 at 6:12
what should i do
– pushpendra chauhan
Nov 14 '14 at 6:19
add a comment |
$usepcontains no integer.
– Cyrus
Nov 14 '14 at 6:12
what should i do
– pushpendra chauhan
Nov 14 '14 at 6:19
$usep contains no integer.– Cyrus
Nov 14 '14 at 6:12
$usep contains no integer.– Cyrus
Nov 14 '14 at 6:12
what should i do
– pushpendra chauhan
Nov 14 '14 at 6:19
what should i do
– pushpendra chauhan
Nov 14 '14 at 6:19
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
The problem is there:
if [ $usep -ge $ALERT ]; then
...
fi
$usep contains multiple lines of digits. To cycle trough all of them use somthing like this instead of that part:
for $space in $usep;
do
if [ $space -ge $ALERT ]; then
echo "Running out of space..."
fi
done
add a comment |
up vote
0
down vote
The value stored in the variable $storage comprises of multiple lines. As a result, $output will also contain multiple lines, and so will $usep.
You can extract and compare all values stored in $usep, one by one, using another for loop as mentioned in this answer. Or you can use while statement as follows:
echo $storage | while read output
do
...
...
if [ $usep -ge $ALERT ]; then
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done
Is this anything other than a repost of the question?
– jasonwryan
Nov 14 '14 at 7:06
I usedwhile, whereas question containsforloop.
– Mandar Shinde
Nov 14 '14 at 7:37
Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
– jasonwryan
Nov 14 '14 at 7:40
I am very poor at explaining things. You could edit my answer if you wish to.
– Mandar Shinde
Nov 14 '14 at 7:42
@jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
– Mandar Shinde
Nov 14 '14 at 8:18
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
The problem is there:
if [ $usep -ge $ALERT ]; then
...
fi
$usep contains multiple lines of digits. To cycle trough all of them use somthing like this instead of that part:
for $space in $usep;
do
if [ $space -ge $ALERT ]; then
echo "Running out of space..."
fi
done
add a comment |
up vote
2
down vote
The problem is there:
if [ $usep -ge $ALERT ]; then
...
fi
$usep contains multiple lines of digits. To cycle trough all of them use somthing like this instead of that part:
for $space in $usep;
do
if [ $space -ge $ALERT ]; then
echo "Running out of space..."
fi
done
add a comment |
up vote
2
down vote
up vote
2
down vote
The problem is there:
if [ $usep -ge $ALERT ]; then
...
fi
$usep contains multiple lines of digits. To cycle trough all of them use somthing like this instead of that part:
for $space in $usep;
do
if [ $space -ge $ALERT ]; then
echo "Running out of space..."
fi
done
The problem is there:
if [ $usep -ge $ALERT ]; then
...
fi
$usep contains multiple lines of digits. To cycle trough all of them use somthing like this instead of that part:
for $space in $usep;
do
if [ $space -ge $ALERT ]; then
echo "Running out of space..."
fi
done
answered Nov 14 '14 at 6:56
chaos
34.8k773115
34.8k773115
add a comment |
add a comment |
up vote
0
down vote
The value stored in the variable $storage comprises of multiple lines. As a result, $output will also contain multiple lines, and so will $usep.
You can extract and compare all values stored in $usep, one by one, using another for loop as mentioned in this answer. Or you can use while statement as follows:
echo $storage | while read output
do
...
...
if [ $usep -ge $ALERT ]; then
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done
Is this anything other than a repost of the question?
– jasonwryan
Nov 14 '14 at 7:06
I usedwhile, whereas question containsforloop.
– Mandar Shinde
Nov 14 '14 at 7:37
Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
– jasonwryan
Nov 14 '14 at 7:40
I am very poor at explaining things. You could edit my answer if you wish to.
– Mandar Shinde
Nov 14 '14 at 7:42
@jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
– Mandar Shinde
Nov 14 '14 at 8:18
add a comment |
up vote
0
down vote
The value stored in the variable $storage comprises of multiple lines. As a result, $output will also contain multiple lines, and so will $usep.
You can extract and compare all values stored in $usep, one by one, using another for loop as mentioned in this answer. Or you can use while statement as follows:
echo $storage | while read output
do
...
...
if [ $usep -ge $ALERT ]; then
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done
Is this anything other than a repost of the question?
– jasonwryan
Nov 14 '14 at 7:06
I usedwhile, whereas question containsforloop.
– Mandar Shinde
Nov 14 '14 at 7:37
Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
– jasonwryan
Nov 14 '14 at 7:40
I am very poor at explaining things. You could edit my answer if you wish to.
– Mandar Shinde
Nov 14 '14 at 7:42
@jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
– Mandar Shinde
Nov 14 '14 at 8:18
add a comment |
up vote
0
down vote
up vote
0
down vote
The value stored in the variable $storage comprises of multiple lines. As a result, $output will also contain multiple lines, and so will $usep.
You can extract and compare all values stored in $usep, one by one, using another for loop as mentioned in this answer. Or you can use while statement as follows:
echo $storage | while read output
do
...
...
if [ $usep -ge $ALERT ]; then
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done
The value stored in the variable $storage comprises of multiple lines. As a result, $output will also contain multiple lines, and so will $usep.
You can extract and compare all values stored in $usep, one by one, using another for loop as mentioned in this answer. Or you can use while statement as follows:
echo $storage | while read output
do
...
...
if [ $usep -ge $ALERT ]; then
echo "Running out of space "$partition ($usep%)" on $(hostname) as on $(date)"
fi
done
edited Apr 13 '17 at 12:36
Community♦
1
1
answered Nov 14 '14 at 6:56
Mandar Shinde
1,40782747
1,40782747
Is this anything other than a repost of the question?
– jasonwryan
Nov 14 '14 at 7:06
I usedwhile, whereas question containsforloop.
– Mandar Shinde
Nov 14 '14 at 7:37
Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
– jasonwryan
Nov 14 '14 at 7:40
I am very poor at explaining things. You could edit my answer if you wish to.
– Mandar Shinde
Nov 14 '14 at 7:42
@jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
– Mandar Shinde
Nov 14 '14 at 8:18
add a comment |
Is this anything other than a repost of the question?
– jasonwryan
Nov 14 '14 at 7:06
I usedwhile, whereas question containsforloop.
– Mandar Shinde
Nov 14 '14 at 7:37
Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
– jasonwryan
Nov 14 '14 at 7:40
I am very poor at explaining things. You could edit my answer if you wish to.
– Mandar Shinde
Nov 14 '14 at 7:42
@jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
– Mandar Shinde
Nov 14 '14 at 8:18
Is this anything other than a repost of the question?
– jasonwryan
Nov 14 '14 at 7:06
Is this anything other than a repost of the question?
– jasonwryan
Nov 14 '14 at 7:06
I used
while, whereas question contains for loop.– Mandar Shinde
Nov 14 '14 at 7:37
I used
while, whereas question contains for loop.– Mandar Shinde
Nov 14 '14 at 7:37
Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
– jasonwryan
Nov 14 '14 at 7:40
Well rather than reprinting the whole script, perhaps just the relevent line and an explanation of why yuo think that is a better approach...
– jasonwryan
Nov 14 '14 at 7:40
I am very poor at explaining things. You could edit my answer if you wish to.
– Mandar Shinde
Nov 14 '14 at 7:42
I am very poor at explaining things. You could edit my answer if you wish to.
– Mandar Shinde
Nov 14 '14 at 7:42
@jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
– Mandar Shinde
Nov 14 '14 at 8:18
@jasonwryan - I've tried to make my answer acceptable to you. Hope this answer makes you happy.
– Mandar Shinde
Nov 14 '14 at 8:18
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f167907%2fbash-getting-integer-expression-expected%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$usepcontains no integer.– Cyrus
Nov 14 '14 at 6:12
what should i do
– pushpendra chauhan
Nov 14 '14 at 6:19