"ps" command not executed in script when using crontab
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
"ps" command not executed in script when using crontab
Hello,
I wrote a simple script to see if firefox is running...
However, the ps command is not executed, when I open the logfile I see: "DEBUG LINE 4" and not DEBUG LINE 5, so "ps -e" is never executed despite using the full path of the ps command.
Here is my script:
#!/bin/bash -l
# simple script to test if firefox is running...
Doing this in cron makes no sense. For one thing you are writing to STDOUT which you don't have access to. For another cron runs programs as root unless your system has PAM configured to allow regular users to enter cron jobs.
I'm not certain if you can reattach a screen session if there is not a terminal to attach the screen session to in the first place. You probably have no terminal open with read/write access for screen to be attached to. In the very least, doing so might need to be done before the ps command, or use a variable for the output of the ps command, and redirect stderr to /dev/null. You may need to use ps to indentify processes running in terminals.
E.G.: ttys=$(ps -o tty -u jschiwal | sed '1d;/^\?/d')
Reason being that if you don't have any terminals open, you don't have permission to read or write to the device.
Lastly, why do you want to launch firefox in the background. Why can't you use your eyes to see if firefox is running. It is an interactive program, not a service that runs in the background.
Well okay, to keep it simple, I removed all that "ps" and "screen" crap, and this is my very simple script now:
To start a (LEGAL) game server at reboot:
When this works, I will attach it to screen afterwards...
same PS command not giving output while using in cronjob
i am facing same issue where manual executing the script giving the result but when we configure the same script on crontab and giving 2>&1 >> output.log its not working.
Any resolution on this.
******************************
#!/bin/sh -c
###edit the following
service=Runner
email=XXXXXXXXXXXXXXXXXXXXXX
PROCESSID=`ps -elf | grep -v grep | grep Runner | awk '{print $4}'`
###stop editing
host=`hostname -f`
D=`date +%c`
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 )); then
echo "$service is running @ $D"
echo "Utlzation of $service"
ps -p $PROCESSID -o %cpu,%mem
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.