Operating System - HP-UX
1753328 Members
4883 Online
108792 Solutions
New Discussion

Re: csh scripts and at/cron command

 
SOLVED
Go to solution
SteveMedals
Occasional Visitor

csh scripts and at/cron command

We are in the process of migrating from Solaris to HP-UX and have a large number of scripts written in csh that are called from at or cron.

 

Is there a way to get the at command to execute csh scripts as we don't have the time or resources to rewrite all of our scripts using the sh shell?

 

Thanks in advance.

5 REPLIES 5
Patrick Wallek
Honored Contributor

Re: csh scripts and at/cron command

at / cron doesn't care what the scripts are written in.

 

To make sure that all of your scripts run with the correct shell ALWAYS place the shell as the first line of the script, preceded by #!.

 

So for all of the scripts you are moving from Solaris to HP-UX, just make sure that this is the VERY FIRST line in the script:

 

#!/usr/bin/csh

 

That way your script will execute with the C-shell.

SteveMedals
Occasional Visitor

Re: csh scripts and at/cron command

Thanks for the reply. 

 

The scripts are set up with "#!/usr/bin/csh" as the first line.  One of the first things our script has is a "source" command to pull in common variables.  The output from executing the at command is "sh[46]: source: not found." which tells me that it is not using the csh to execute.  Here is one of the simpler scripts we are trying to run

 

 

#!/usr/bin/csh
#
# /*****************************************************************************
# * PROJECT : TransMon *
# * FUNCTION : *
# * DESCRIPTION : Schedule the script load_transmon_schedule.sh *
# * AUTHOR : Jaya Manoranjani Mekala *
# * DATE : May 12 2007 *
# * OUTPUT : None *
# *
echo "TransMon starting on Westlake Cps1."
source /opt/cps/transmon/scripts/load_control_transmon.var

set to = "apdev"
set toPager = "apdevPager"
set subject = "Load TRANSMON Schedule Start is on HOLD"
set body = "load_transmon_schedule_start.sh was placed on HOLD."
set execute = `echo "${transmon_sched_start}" | tr '[:lower:]' '[:upper:]'`
set pagerSubject = "Load TRANSMON Schedule Load Error"
set pagerBody = "Load TRANSMON Schedule Start is on HOLD as transmon_sched_start load status is: $execute"
echo Execut is $execute
echo $body
echo $load

Steven Schweda
Honored Contributor
Solution

Re: csh scripts and at/cron command

> at / cron doesn't care what the scripts are written in.

 

   I seldom use these things, so I know nothing, but that's what I'd've
said, and my quick test agreed:

 

dyi# uname -a
HP-UX dyi B.11.31 U ia64 4235313755 unlimited-user license

 

dyi# ls -l ct*
-rwxr-xr-x 1 root sys 49 Jun 23 12:43 ct.csh
-rw-r--r-- 1 root sys 17 Jun 23 12:42 ct2.cs

 

dyi# cat ct.csh
#!/usr/bin/csh

 

source ~root/ct2.cs

 

echo 'Done'

 

dyi# cat ct2.cs
echo ' ct2.cs'

 

dyi# date
Tue Jun 23 22:54:59 CDT 2015

 

dyi# echo '/root/ct.csh' | at 22:56
warning: commands will be executed using /usr/bin/sh
job 1435118160.a at Tue Jun 23 22:56:00 2015

 

   And the mail I got said:

 

From root@dyi.antinode.info Tue Jun 23 22:56:01 CDT 2015
[...]
Subject: at

 

   ct2.cs
Done


*************************************************
Cron: The previous message is the standard output

      and standard error of one of your at commands.

 


    The "man" page also talks about "/usr/bin/sh" doing all the work, but
if the script itself has a "#!" line, then /usr/bin/sh should run that
interpreter, which is what seems to happen here.

 

   Does your script have "x" permission, and are you sure that you're
running the one which you think you're running?  Does it work if you run
it interactively?

SteveMedals
Occasional Visitor

Re: csh scripts and at/cron command

There was a difference in how you called at and how we are calling at.  We were using 'at -f script.sh now'.  Trying to run our scripts using "echo 'script.sh' | at now" worked for us.

 

Thanks for the assistance

Dennis Handly
Acclaimed Contributor

Re: csh scripts and at/cron command

>We were using "at -f script.sh now".


This tells at(1) to fiddle with the source file and prefix the Posix shell script with more Posix shell commands.  Which won't work for the scummy C shell.

 

at(1) says: Enter commands from ...

And it does say by the Posix shell.

 

>Trying to run our scripts using "echo 'script.sh' | at now" worked for us.

 

This tells at(1) to execute the script with the single command "script.sh" from the Posix shell.

You may want to make this more efficient by:

   echo 'exec script.sh' | at now

 

>at / cron doesn't care what the scripts are written in.

 

Quite the contrary, at(1) does but cron(1) doesn't.

(Unless for the latter you actually have a csh command in the crontab file. :-)