Unix Technical Forum

crontab problem

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 ...


Go Back   Unix Technical Forum > Unix Operating Systems > Solaris Operating System > Sun Solaris Administration

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-16-2008, 10:35 AM
Fuliggians
 
Posts: n/a
Default crontab problem

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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-16-2008, 10:35 AM
Greg Andrews
 
Posts: n/a
Default Re: crontab problem

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-16-2008, 10:35 AM
Fuliggians
 
Posts: n/a
Default Re: crontab problem

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."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-16-2008, 10:35 AM
Casper H.S. Dik
 
Posts: n/a
Default Re: crontab problem

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-16-2008, 10:35 AM
Othmar Wigger
 
Posts: n/a
Default Re: crontab problem

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:
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-16-2008, 10:35 AM
tomfi
 
Posts: n/a
Default Re: crontab problem

Fuliggians napsal(a):
> hi all,
>
> here my problem:
> I've got this bash script very simple that work fine if I run it via
> shell
> $ ./test.sh
>

hi... test
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:22 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com