Hi everyone,
I've got a few scripts running with crontab and I know they are actually running thanks to a log file.
The thing is, each time I type ps -ef | grep .sh (because my scripts are .sh files) i have no results.
I read that crontab was using its own environment to execute his scripts and so I was wondering if ps command was able to detect them.
I'm a newbie to Linux environment, so I'm sorry if my question might seem obvious. Thanks
If you run ps while your script is running, then ps will report that process.
crond is the cron process, and it belongs to root. When crond notices that it's time for your process to run, it will fork a process, change that process's user to your ID, then exec() your script.
This process will appear in ps, if ps is run while it's active, but if the process is short-lived, you only have a short window of opportunity to glimpse it..
Related
I have created some cron jobs in cpanel and deleted. But some of them are still running.
How can I find where these are stored and delete them?
Can I use Cpanel terminal for this?
Or in which files or database table could they be stored so that I can delete them from there?
With the following command, you can see the list of crons and the items that do not have #(comment) will be executed.
run with the root user or the user you use
crontab -e
if you have access to Cpanel terminal as a non-root user. at first find the pid of your processes and then kill them.
ps -aux | grep ProcessName
for example if your process related to python or java write them.
kill -9 pid
now kill your proccess.
for finding pid of your process also you can use top command and then type c from your keyboard and then find your process.
Please check your WordPress db
Login into PHPMyAdmin and select your WordPress database
The wp_options table record that storages cron data (option_name = ‘cron’) in the database and the cron job has disappeared.
Regards
I wrote a python script to work with a message queue and the script was launched by crontab. I removed from crontab but the root user of my linux system keeps launching it every 9 minutes.
I've rebooted system and restarted cron but this script keeps getting executed.
Any idea how to keep it from happening?
If you start a cron, service does not stop even if you delete the file in which you have specified the cron.
This link should help:
https://askubuntu.com/questions/313033/how-can-i-see-stop-current-running-crontab-tasks
Also, you can also kill your cron by looking its PId, using: ps -e | grep cron-name, then kill -9 PId
I have a bash script running on Ubuntu.
Is it possible to see the line/command executed now without script restart.
The issue is that script sometimes never exits. This is really hard to reproduce (now I caught it), so I can't just stop the script and start the debugging.
Any help would be really appreciated
P.S. Script logic is hard to understand, so I can't to figure out why it's frozen by power of thoughts.
Try to find the process id (pid) of the shell, you may use ps -ef | grep <script_name>
Let's set this pid in the shell variable $PID.
Find all the child processes of this $PID by:
ps --ppid $PID
You might find one or more (if for example it's stuck in a pipelined series of commands). Repeat this command couple of times. If it doesn't change this means the script is stuck in certain command. In this case, you may attach trace command to the running child process:
sudo strace -p $PID
This will show you what is being executed, either indefinite loop (like reading from a pipe) or waiting on some event that never happens.
In case you find ps --ppid $PID changes, this indicates that your script is advancing but it's stuck somewhere, e.g. local loop in the script. From the changing commands, it can give you a hint where in the script it's looping.
I made a python script running on background:
nohup python app.py &
then close the terminal, a few days later, I want to see this job, so I run
jobs
there list no jobs, but I'm sure the script app.py is still running.
jobs will only give you a list of process running under the session group of the bash shell. nohup processes run in their own session group. There are a number of simple commands you can run to check if your nohup'd process is still running, the simplest being lsof | grep nohup (this command may take a few seconds to run)
Well, I'm basically trying to make a bash script runs a node script forever. I made the following bash script:
#!/bin/bash
while true ; do
cd /myscope/
unlink nohup.out
node myscript.js
sleep 6
done & echo $! > pid
I'm expecting that when it runs, it starts up node with the given script, checks if node exits, sleeps for 6 seconds if so and reopen node. Also, I'm expecting it to run in background and writes it's pid (the bash pid) on a file called "pid".
Everything explained above works as expected, apparently, but I'm also expecting that when the pid of the bash script is killed, the node script would stop running, I don't know why that made sense in my mind, but when it comes to practice, it doesn't work. The bash script is killed indeed, but the node script keeps running and that is freaking me out.
I've tested it in the terminal, by not sending the bash script to the background and entering ctrl+c, both scripts gets killed.
I'm obviously miss understanding something on the way the background process works. For god sake, can anybody help me?
There are lots of tools that let you do what you're trying, just two off the top of my head:
https://github.com/nodejitsu/forever - A simple CLI tool for ensuring that a given script runs continuously (i.e. forever)
https://github.com/remy/nodemon - Monitor for any changes in your node.js application and automatically restart the server - perfect for development
Maybe the second it's not what you're looking for, but still worth a look.
If you can't or don't want to use those then the problem is that if you kill the parent process the child one is still there, so, you should kill that too:
pkill -TERM -P $PID
where $PID is the parent PID.