This is a discussion on crontab problem within the Sun Solaris Administration forums, part of the Solaris Operating System category; --> hi all, here my problem: I've got this bash script very simple that work fine if I run it ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| hi all, here my problem: I've got this bash script very simple that work fine if I run it via shell $ ./test.sh I want to use it with crontab and in this case the system generate 2 problems: 1) I know that crontab do not Inherit the paths etc... in this case I tried to insert - as described in many forums - PATH HOME etc... directly in the cron file here the first problem. I can't add anything in the cron except the usual format (like * * * * * /test.sh) so I puth the path directly inside the test script. I don't like it but it works. Why I'm not able to edit also the path inside the cron? I tried both with su and normal user 2) the very first lines of test.sh are: File=/Script1/beta80/varDB.sh { while read riga # Per tutte le righe del file di input... do if [ ${riga:0:1} = '/' ] then tmp=${riga:1} parametro=${tmp%%=*} # Estrae il nome. valore=${tmp##*=} # Estrae il valore. eval $parametro=$valore fi done }<$File I've got the error: /test.sh: bad substitution I try to insert "#!/bin/sh -xv", "#!/bin/sh" "#!/bin/ksh", but I always have the same problem. I also try to go into /bin and run sh ./test.sh, and I have the same problem. Why? This is very strange for me. The script is able to run normally if I do not specify any "sh" thanks in advance for your help |
| |||
| Fuliggians <fuliggians@gmail.com> writes: > >here my problem: >I've got this bash script very simple that work fine if I run it via >shell >$ ./test.sh > >I want to use it with crontab >and in this case the system generate 2 problems: > >1) I know that crontab do not Inherit the paths etc... >in this case I tried to insert - as described in many forums - PATH >HOME etc... directly in the cron file >here the first problem. I can't add anything in the cron except the >usual format (like * * * * * /test.sh) >so I puth the path directly inside the test script. I don't like it >but it works. Why I'm not able to edit also the path inside the cron? >I tried both with su and normal user > You have bash-specific commands in your script, but you don't seem to have the line that make sure bash will interpret your script. Is the very first line of your script: #!/usr/bin/bash If not, the SunOS/Solaris cron will try to run your script with the Bourne shell, which doesn't understand the bash-specific commands. -Greg -- Do NOT reply via e-mail. Reply in the newsgroup. |
| |||
| On 19 Nov, 17:53, g...@panix.com (Greg Andrews) wrote: > Fuliggians <fuliggi...@gmail.com> writes: > > >here my problem: > >I've got this bash script very simple that work fine if I run it via > >shell > >$ ./test.sh > > >I want to use it with crontab > >and in this case the system generate 2 problems: > > >1) I know that crontab do not Inherit the paths etc... > >in this case I tried to insert - as described in many forums - PATH > >HOME etc... directly in the cron file > >here the first problem. I can't add anything in the cron except the > >usual format (like * * * * * /test.sh) > >so I puth the path directly inside the test script. I don't like it > >but it works. Why I'm not able to edit also the path inside the cron? > >I tried both with su and normal user > > You have bash-specific commands in your script, but you don't seem > to have the line that make sure bash will interpret your script. > Is the very first line of your script: > > #!/usr/bin/bash > > If not, the SunOS/Solaris cron will try to run your script with the > Bourne shell, which doesn't understand the bash-specific commands. > > -Greg > -- > Do NOT reply via e-mail. > Reply in the newsgroup. Thanks! Yeah! But now I have to solve also the point 1. Infact if I'm not able to add inside the cron file the PATH, some other Perl script are not able to run, because they can't find some modules. This is crazy: why am I not able to specify the PATH in the cron file? also as root this is impossible, this is the error it generate when I try to save the file: "crontab: error on previous line; unexpected character found in line. crontab: errors detected in input, no crontab file generated." |
| |||
| Fuliggians <fuliggians@gmail.com> writes: >Infact if I'm not able to add inside the cron file the PATH, some >other Perl script are not able to run, because they can't find some >modules. Scripts run from crontab must be self-contained: they need to setup $PATH and the rest of the environment i fanything is needed over the default (which is pretty barren) >This is crazy: why am I not able to specify the PATH in the cron file? >also as root this is impossible, this is the error it generate when I >try to save the file: >"crontab: error on previous line; unexpected character found in line. >crontab: errors detected in input, no crontab file generated." Because crontab is a crontab file and not a shellscript; we are planning to extend the crontab syntax somewhat to possibly allow such things, but wrapping it up in a single script which takes care of everything is the only portable way to go about this business. Casper -- Expressed in this posting are my opinions. They are in no way related to opinions held by my employer, Sun Microsystems. Statements on Sun products included here are not gospel and may be fiction rather than truth. |
| |||
| On 20 Nov., 10:58, Fuliggians <fuliggi...@gmail.com> wrote: > Infact if I'm not able to add inside the cron file the PATH, some > other Perl script are not able to run, because they can't find some > modules. > This is crazy: why am I not able to specify the PATH in the cron file? There are at least two ways to do it, if read man cron carefully: 1) use Bourne shell syntax in the crontab file, like * * * * * PATH=/usr/bin:/mypath ./test.sh 2) set a default PATH for all cron jobs in /etc/default/cron CRONLOG=YES PATH=/usr/bin:/mypath: |