Carl,

I'd suggest explicitly setting a PATH in the script and also using "&"
to put the job in the background (via cron):

* * * * * /path/to/some/binary /path/to/some/script &

John DeSantis

2015-04-02 4:22 GMT-04:00 Inigo Aldazabal Mensa <[email protected]>:
>
> On Wed, 01 Apr 2015 19:27:55 -0700
> "Carl E. Fields" <[email protected]> wrote:
>
>> hello everyone,
>>
>> thank you for your responses.
>>
>> I've tried moving everything to one file 'test.sh'
>> with the contents below:
>
> I'm not a bash expert but two suggestions:
>
> 1) Perhaps better use "set -e" instead of all those &&? See
> http://www.davidpashley.com/articles/writing-robust-shell-scripts/#id2382181
>
> 2) Redirect sbatch both stdout and stderr to some output file in order
> to better know what happens: "sbatch calculate.job &> sbatch.out"
>
> Also, I guess you'll have some motivation but, why do you use a bang.sh
> script instead of just calling sbatch straight from the main one?
>
> Inigo
>
>>
>> #!/bin/bash
>>
>>
>> if [ -f inlist_user_input ]
>>
>>     then
>>
>>      cd /var/www/virtual/mesa-web.asu.edu/html/services &&
>>
>>      cp inlist_user_input /var/www/virtual/
>> mesa-web.asu.edu/html/services/Work/ &&
>>
>>      rm /var/www/virtual/mesa-web.asu.edu/html/services/inlist_user_input
>> &&
>>
>>      cd /var/www/virtual/mesa-web.asu.edu/html/services/Work &&
>>
>>      ./bang.sh
>>
>>     else
>>
>>    exit
>>
>> fi
>>
>>
>> where bang.sh:
>>
>>
>>
>> #!/bin/bash
>>
>> whoami > 'out.txt'
>>
>> sbatch calculate.job
>>
>>
>>
>>
>> Where calculate.job:
>>
>> #!/bin/bash
>>
>> #SBATCH -p compute
>>
>> #SBATCH -N 1
>>
>> #SBATCH -n 1
>>
>> #SBATCH --time=00:10:00
>>
>> #SBATCH --mail-type=ALL
>>
>> #SBATCH [email protected]
>>
>> #SBATCH --error=job.%J.err
>>
>> #SBATCH --output=job.%J.out
>>
>>
>>
>> srun ./rn
>>
>>
>>
>>
>>
>> crontab executes eve thing fine except the batch command, which works
>> when run as SlurmUser by hand. I have the bang script before the
>> batch is being executed, print the user, to ensure its the slurm user.
>>
>>
>> Any further suggestions would be welcomed.
>>
>>
>> Thanks,
>>
>>
>> Carl
>>
>>
>>
>>
>>
>> On Wed, Apr 1, 2015 at 2:19 PM, Inigo Aldazabal Mensa <
>> [email protected]> wrote:
>>
>> >
>> > On Wed, 01 Apr 2015 13:13:38 -0700
>> > "Carl E. Fields" <[email protected]> wrote:
>> >
>> > > Hi Everyone,
>> > >
>> > > I wish to have crontab check every minute for the existence of a
>> > > file, then if such file exists, execute "sbatch calculate.sh".
>> > >
>> > > crontab is written as:
>> > >
>> > > * * * * * SlurmUser
>> > > cd /var/www/virtual/mesa-web.asu.edu/html/services
>> > > && /bin/sh ./test.sh
>> > >
>> > > the file test.sh contains:
>> > >
>> > > #!/bin/bash
>> > >
>> > >
>> > > if [ -f inlist_user_input ]
>> > >
>> > >     then
>> > >
>> > >     sbatch calculate.sh > 'rn.txt'
>> > >
>> > >     else
>> > >
>> > >    exit
>> > >
>> > > fi
>> > >
>> > >
>> > >
>> > > lastly, calculate.sh is a typical job batch script
>> > >
>> > > When i $ ./test.sh by hand
>> > >
>> > > I get the typical out put "Submitted job id ##" to the rn.txt file
>> > >
>> > > However, when I have crontab do the same thing,
>> > > rn.txt is created, but empty.
>> > >
>> > > Can crontab processes execute sbatch commands? Am I missing a
>> > > particular permission setting?
>> >
>> > Are you sure calculate.sh is in the same path where sbatch is run
>> > from?
>> >
>> > If it's not sbatch will just dump an error, which output would no
>> > be in your rn.txt as it'd go to stderr, and exit.
>> >
>> > I'd add the cd part to the test.sh script itself.
>> >
>> > Inigo
>> >
>> >
>> > > all files involved are executable by "SlurmUser"
>> > >
>> > > Thanks ahead of time,
>> > >
>> > > Carl
>> >

Reply via email to