Running a user crontab

Hi,

I tried to 'cron' a small script using username 'ookla' as indicated below but is facing problem running. This should enable a 'pingserver' to run on tcp/udp port 8080

# crontab -u ookla -l
Code:
* * * * * ~/pingtest.sh 2>&1

However manual starting the 'daemon' confirms it works.

Code:
$ java -jar Server.jar --tcpPort 8080 --udpPort 8080
LOG     Mon, 28 Nov 2011 12:52:13 +1200 MAIN    No IP Specified, will use: xxx.xx.25.245
LOG     Mon, 28 Nov 2011 12:52:13 +1200 MAIN    Start UDP Thread
LOG     Mon, 28 Nov 2011 12:52:13 +1200 MAIN    Start TCP Listener
LOG     Mon, 28 Nov 2011 12:52:13 +1200 S-TCP   Listening on port: 8080
I wonder if I am missing something on my 'cron' job?
Please assist...


Best regards,
Waqa
 
Hi wblock@,


Code:
#!/bin/sh

if [ `ps x | grep VoipServer | grep -v grep | grep -vi screen | wc -l` = "0" ]
then
  cd ~/
  java -Xmx256m -jar VoipServer.jar --tcpPort 8080 --udpPort 8080 > /dev/null &
fi
~
~
As requested, I will try the absolute path and verify as well. By the way this is on FreeBSD 8.1.



Regards,
Rwaqa
 
If you are starting a server that is going to be running all the time, why are you running it every minute?

I'm guessing the if-statement in your shell script is to check if the program is running. It might be better to have a PID-file, where you can enter the PID. When starting the program you can check if the file exists, and if it exists you can proceed to do nothing, or restart/stop it should this be necessary.
 
Ok, got a message for /var/mail/ookla as attached below and looks the issue is about permission. How can user 'ookla' be allowed to run cron on Freebsd 8.1?

Code:
Date: Tue, 29 Nov 2011 04:13:00 +1300 
Message-Id: <201111281513.pASFD0FQ011635@host1.connect.com>
From: [email]ookla@host1.connect.com[/email] (Cron Daemon)
To: [email]ookla@host1.connect.com[/email]
Subject: Cron <ookla@host1> /home/ookla/pingtestcheck.sh 2>&1
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/ookla>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=ookla>
X-Cron-Env: <USER=ookla>

/home/ookla/pingtestcheck.sh: Permission denied

mix_room,

This is needed to be run every minute as a requirement from our overseas partner who provides this particular service


Thanks guys
Waqa
 
Thank you SirDice,

Yes, changing the file script to executable made cron work. But I have another issue pop up, /var/mail says
Code:
java not found

Code:
From: [email]ookla@host1.connect.com[/email] (Cron Daemon)
To: [email]ookla@host1.connect.com[/email]
Subject: Cron <ookla@host1> /home/ookla/pingtestcheck.sh 2>&1
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/ookla>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=ookla>
X-Cron-Env: <USER=ookla>

java: not found

/home/ookla
$ ls -l
total 44
-rw-r--r--  1 ookla  wheel  40280 Nov 25 18:05 VoipServer.jar
-rw-r--r--  1 ookla  wheel     34 Nov 29 03:45 pingtest.cron
-rwxr-xr-x  1 ookla  wheel    186 Nov 29 03:46 pingtestcheck.sh
However manually checking confirms java works!
Code:
$ java -jar VoipServer.jar --help

Usage:
  VoipServer [--help] --tcpPort <tcpPort> --udpPort <udpPort> <externalIp>

Server Daemon for the Ookla Voip Test and the Line Quality Test


  [--help]
        Prints this help message.

  --tcpPort <tcpPort>
        The port the server will bind to for TCP features. (default: 5060)

  --udpPort <udpPort>
        The port the server will bind to for UDP features. (default: 5060)

  <externalIp>
        IP used to access the server (default: interface IP) (default: local)

Please help.

Thankyou in advance.
Waqa
 
Not so sure how to.

Can I add a line to /home/ookla in .profile specifying
Code:
X-Cron-Env: <PATH=/home/ookla/VoipServer.jar>



Thankyou,
Waqa
 
cron does not log in as the user, so it does not have the full user environment. Again, use full paths in the script:
Code:
/usr/local/bin/java ...

or, more readably:
Code:
JAVA="/usr/local/bin/java"

$JAVA ...

or, more precisely:
Code:
JAVA="/usr/local/bin/java"

${JAVA} ...
 
wblock@,

So I edit crontab and should read as below;

Code:
JAVA="/usr/local/bin/java"
${JAVA}
* * * * * /home/ookla/pingtestcheck.sh 2>&1

Almost there I guess.


Thanks,
Waqa
 
Ok, managed to change the full path java on crontab but error message received from /var/mail/ookla as seen below;

Code:
From: [email]ookla@host1.connect.com[/email] (Cron Daemon)
To: [email]ookla@host1.connect.com[/email]
Subject: Cron <ookla@host1> /home/ookla/pingtestcheck.sh 2>&1
X-Cron-Env: <PATH=/usr/local/bin/java>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/ookla>
X-Cron-Env: <LOGNAME=ookla>
X-Cron-Env: <USER=ookla>

ps: not found
grep: not found
grep: not found
grep: not found
wc: not found
[: =: unexpected operator
Hope this helps in isolating my issue.


Thanks.
 
Noted DutchDaemon,

I guess the error log below relates to the script in my pingtestcheck.sh. Note, grep, wc, are commands in the script pingtestcheck.sh. Please help as this the last piece in my project to work.

Code:
Subject: Cron <ookla@host1> /home/ookla/pingtestcheck.sh 2>&1
X-Cron-Env: <PATH=/usr/local/bin/java>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/ookla>
X-Cron-Env: <LOGNAME=ookla>
X-Cron-Env: <USER=ookla>

ps: not found
grep: not found
grep: not found
grep: not found
wc: not found
[: =: unexpected operator
 
rwaqa said:
So I edit crontab and should read as below;

Code:
JAVA="/usr/local/bin/java"
${JAVA}
* * * * * /home/ookla/pingtestcheck.sh 2>&1

Almost there I guess.
Close.

The JAVA definition should be in your script, not in the crontab.
 
Thankyou so much SirDice and all who assisted.
My java is running now on its own;)

Code:
38889 ookla      10  76    0   406M 17192K sbwait   0:00  0.00% java


Big Cheers to all you guys:)



RWaqa
 
rwaqa said:
wblock@,

So I edit crontab and should read as below;

Code:
JAVA="/usr/local/bin/java"
${JAVA}
* * * * * /home/ookla/pingtestcheck.sh 2>&1

Almost there I guess.

No, put that in the script, along with definitions for all the other external commands. The only thing in the crontab should be the full path to the script.
 
Back
Top