Visit Our UNIX and Linux User Community

Can run a ".sh" script as the user but not from the crontab

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can run a ".sh" script as the user but not from the crontab
# 8  
Old 09-10-2009
The Script is behaving wierdly

Thank you guys for all the suggestions. I put the full path and the script and now works good.

Originally Posted by Vi-Curious
Another minor observation. This says run your script every hour on the half hour.
Yes, that is correct.

One thing I have noticed though is that the script is behaving weirdly and that the script is running "" even though it shouldn't.

I added one more line to my script to give me little more details in the log file. The new line is highlighted in bold letters.

m=`ps -ef | grep /install/new/application | wc -l`
if [ $m != 2 ]; then
echo "`ps -ef | grep /install/new/application`"
echo "starting application"
echo "done"
echo "no action taken";

As you see the code says run "" only when the value of $m is not equal to 2. But I found that once in a while the script runs "" even though the value of m = 2. This happens some times and not always. Here are the excerpts from my log file.

no action taken
no action taken
no action taken
no action taken
 bhaire 22082     1  0   Sep 09 ?        4:58 /install/new/application
 bhaire 11402 11394  0 14:45:00 ?        0:00 grep /install/new/application
starting application
no action taken
no action taken

Shouldn't the value for "wc -l" be 2. But still why does it go and start ""?

Thanks in advance.

Last edited by bhaire; 09-10-2009 at 01:45 PM..
# 9  
Old 09-10-2009
bhaire 22082 1 0 Sep 09 ? 4:58 /install/new/application
This process is a background process with a PPID of 1 . I suspect the the first "ps" in your script picked up the script or program which started the process "/install/new/application". That isn't in a cron as well is it?

There are other minor issues in the script. You are doing a text compare when a numeric compare would be better. There is a spurious semi-colon near the end of the script. Your highlighed line does not need the echo. Indentation makes scripts easier to follow.

m=`ps -ef | grep "/install/new/application" | wc -l`
if [ $m -ne 2 ]
	ps -ef | grep "/install/new/application"
	echo "starting application"
	echo "done"
	echo "no action taken"

If the user is always "bhaire", "ps -fubhaire" is more efficient than "ps -ef".
# 10  
Old 09-11-2009
Change the code to follows:
m=`ps -ef | grep "/install/new/application" | grep -v grep`
if [ $? = 0 ]

# 11  
Old 09-14-2009
I made the code cleanup like Methyl suggested and it looks a lot better. I followed Edidataguy's suggestion and added grep -v grep and its working like a charm.

Thank you for all your help and suggestions.

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to run root level command , if user has "su -" permission in sudoers provided?

I am looking t run root level command on multiple servers, but all servers have only "su - " permission available in sudoers. please help me if any way that I can run command using help of "su -" My script for hosts in `cat hosts.txt`; do echo "###########################Server Name-... (5 Replies)
Discussion started by: yash_message
5 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

What is the significance of sh -s in ssh -qtt ${user}@${host} "sh -s "${version}"" <

Please can you help me understand the significance of providing arguments under sh -s in > ssh -qtt ${user}@${host} "sh -s "${version}"" < (4 Replies)
Discussion started by: Sree10
4 Replies

4. Shell Programming and Scripting

Shell script using expect to login to couple of remote servers and read "crontab -l"

I need a shell script using expect to login to couple of remote servers and read "crontab -l -u <username>" & "cat /etc/rc.local" & "df -h" and able to create output into a file saved locally with hostname.crontab & hostname.rc.local & disk.status. I can supply a file as list of hostname or IP... (4 Replies)
Discussion started by: jaipsharma
4 Replies

5. Shell Programming and Scripting

Crontab not running "nail" in script

the script is in Perl... this is one part of it: $command = "echo \"$text\" | /usr/bin/nail -s \"My $text1\" $ccstr$addstr"; system("$command") if length($bodytext)>1; crontab runs the script and sends me notifications but i cant receive any mail that i wanted! I'm using the complete path... (1 Reply)
Discussion started by: yeean
1 Replies

6. UNIX for Dummies Questions & Answers

crontab does not run "root" job

hi, I've read different posts regarding crontab but none helped out...the shell scrip that I want to run through crontab gets run through crontab when I use the following crontab statement: 13 17 * * * /usr/net/gcc/ > /usr/net/gcc/DBdrop.log 2>&1 but it does not run when I scheduel... (2 Replies)
Discussion started by: linux0004
2 Replies

7. UNIX for Dummies Questions & Answers

Possible to give non root user sudo to "crontab -l"

Does anyone know if this is possible? I want to give some users access to root's crontab but only with a read privilege. Is this possible to do or can only root or people with full root sudo view root's cron? (4 Replies)
Discussion started by: LordJezoX
4 Replies

8. Shell Programming and Scripting : need combination from "start" and "run"

heya, can someone help me with following problem. i am not sure how far you know the script from tomcat. when i start my tomcat with " run" then the startup-process-output will be printed out on the console, but the tomcat process is started in current shell/session, so... (1 Reply)
Discussion started by: Filly
1 Replies

9. Shell Programming and Scripting

communicating wth another user aside from "wall" and "write"

Hi, Can anyone suggest a Unix command or c-shell algorithm to simulate to behavior of "wall" command minus the "all users"? What I'm trying to do is to send a notice to just one particular user but i dont want other remotely-logged-on users to receive the message (on the pseudo-terminals). I... (6 Replies)
Discussion started by: Deanne
6 Replies

10. UNIX for Dummies Questions & Answers

Run away "bootpgw" & "inetd"

Hello All. I'm get the following messages posted to the /var/adm/syslog file ever second and not sure on how to stop the process. May 14 15:50:52 a3360 bootpgw: version 2.3.5 May 14 15:50:52 a3360 inetd: /etc/bootpgw exit 0x1 As said about this gets logged every second only thing that... (4 Replies)
Discussion started by: cfaiman
4 Replies

Featured Tech Videos