Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cron job runs under wrong shell 1

Status
Not open for further replies.

cp2000

Technical User
Dec 31, 2002
81
US
I am running Solaris 8 trying to run a compiles executable. I am the sysadmin. One of our developers created the program.

The problem I have is.....I need to run the program as a cron job. AND it needs to run under the tcsh shell. This IS the default shell for the user running the cron job (not root).
I have tried wrapping ina script something like:
#!/bin/tcsh
/path/program

That runs fine interactively AND under the "at" command. HOWEVER....as soon as I try to run it as a user cron job it fails. I added "setenv" to the script and found that interactively and under "at" it is correctly using the tcsh shell. however when run as a cron job it is using /bin/sh.

Have I missed something? My understanding is that the first line of the script defines the shell.

Eda - cate Me

Thanks
 
Have you tried envoking the tcsh shell in the script before you run the program (not just have it listed at the top of the script)?
 
my understanding is the first line of the script done in that syntax IS invoking the shell. At least that's how I've always done it before.
 
Yes, that is usually the way it works. But it isn't working like that for you, right?

When you edit cron, you usually get a message telling you that all scripts run from cron are run in the sh shell. Just a suggestion to add invoking the shell in the script you are running from cron.
 
Ok, Let me try again. somehow we am not communicating.

When I started having problems, I created a shell script. The first line of that shell script is
#!/bin/tcsh
My understanding and experience has been that invokes the tcsh shell. Running the script from the cron job though does not seem to invoke the shell.
 
Yes, we are not communicating. Here's an expanded version:

I said that when you edit crontab (crontab -e) and save the file, you get a message saying that all scripts run from cron are run under the Bourne shell. For some reason, Solaris' cron ignores the shebang line in a script -- its "rule" of running scripts in cron using the Bourne shell overrides that line, it seems.

I suggested that, as part of the script you are running from cron, that you add invoking the tsch shell.

I suggest your script look like this:

#!/bin/sh
/bin/tcsh /path/program

My second message agreed with you that yes, the shebang at the top of the script is what usually invokes the shell to be used in the script. I also said that apparently this isn't working for you and made a suggestion that would work around this assumed behavior of scripts.

You might want to take a look at the suggestions in thread60-295507. The first suggestion made there you already know doesn't work. The second suggestion (invoking the tcsh shell before you kick off the program), is what I am suggesting you try.



 
I have been having the same problem with tcsh.
I think I might have worked out a solution, tho I've not tested it fully yet.
I've been testing with my root crontab as -
00 8 * * * (exec tcsh </usr/script.sh &)

My script.sh test file simply does a sleep 120, and I see the parent PID becomes 1 (Unix kernel), and the sleep running as a child of tcsh.

For good measure I also have #! /bin/tcsh at the start of the script.

Hope this helps
Bob

 
Sorry..
crontab should read -
00 8 * * * (exec /bin/tcsh </usr/script.sh &)

Bob
 
why not just invoke the shell in the script rather than in cron????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top