Results 1 to 3 of 3
Hi ,
I am a novice Linux user and have created a simple shell script which is giving me the following error "exit: 29: Illegal number: 2" when I used ...
- 12-04-2007 #1Just Joined!
- Join Date
- Nov 2007
- Posts
- 8
Shell scriptin : Illegal number error message
Hi ,
I am a novice Linux user and have created a simple shell script which is giving me the following error "exit: 29: Illegal number: 2" when I used the exit command.
I am not able to understand whats the error for.
kindly help me with this.
code:
#!/bin/sh
# The entries of syslog are stored in storelogs
storelogs=/var/log/syslog
badUser=student
## temp file
temporary=/tmp/temp1.txt
echo $badUser
#Taking the entry student and sending it to the temp file
grep $badUser /var/log/syslog > /dev/null
##echo $?
if [ $? -eq 0 ];then
echo $badUser >> /tmp/temp1
fi
grep -s $badUser /var/preserve/glopes/glopes.txt
echo $?
if [ $? -eq 0 ];then
echo "No mail"
exit 2 //////////////////// ERROR LINE
fi
- 12-04-2007 #2
Well, I can't find much online, but try changing your shebang from "/bin/sh" to "/bin/bash". Apparently that fixed someone else's problem (which looks similar). Anyway, a few notes on other parts of your script:
Don't rely on the value of $?. This is because you tend to accidentally change it. For instance, before your last if-statement, you echo out the value. Now no matter what the value was, it is now 0 (as echo's return value will be 0). It is better to save the value in some variable of your own, and use that for comparisons.
Also, you're trying to see if grep finds a particular entry in the file. The designers of grep considered that, and added a '-q' (quiet) option that makes life easier. Read grep's man page for more info, but you would use it like this:
If you don't use "test" (or "[ ... ]") in your if-statements, then a 0 is considered true, and a non-zero is considered false (this is the inverse of using "[ ... ]"). This is because when a program is successful, it returns 0. So here, by using the '-q' option, grep will return with a 0 exit status if it finds even a single match. It also won't print out anything.Code:if grep -q "$badUser" /var/log/syslog; then echo $badUser >> /tmp/temp1 fi
Does this make sense?DISTRO=Arch
Registered Linux User #388732
- 12-04-2007 #3Just Joined!
- Join Date
- Nov 2007
- Posts
- 8
Thaanks Cabhan!!
This is my first post asking for help and I really appreciate the prompt reply that you have given.
It helped me solve the issue.


Reply With Quote