How to detect which process is run by what?


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to detect which process is run by what?
# 1  
Old 09-01-2019
How to detect which process is run by what?

Hello,
I am running under ubuntu 14.04
Very long time ago, I set a script (ban.sh) to block ip addresses abusing my system which was not active.
I have not touched the server over six months or more.
Today, after restart the system, ban.sh started running all of a sudden and keep submitting email to me every 2/3 minutes.
I put # in front of my ban.sh task in crontab -e
/etc/crontab has no rule.
After this change, it keeps sending me emails. Does it require hardware reboot or network restart to make activate the changes or how may I know which process/script is forcing ban.sh to start again?

PS: As a palliative solution, I have ran apt-get autoremove mail*
Thank you
Boris

Last edited by baris35; 09-01-2019 at 10:03 AM..
# 2  
Old 09-01-2019
I'm not sure what you're asking here but I think it's about how to stop crontab running a job.

If you use the crontab command to create or cancel or modify a schedule then the crontab daemon should get signalled immediately and modify its behaviour. If you edit the crontab files directly then it could take up to 24 hours to take effect because the crontab daemon doesn't know about the change. To get an immediate effect in this case you would need to issue a command to restart the cron daemon from a root privileged account.

On Ubuntu the cron tables themselves are located at /var/spool/cron/crontabs. There is one file for each user with cron jobs scheduled and you can cat these to see the contents (but, by the book, you shouldn't edit them).

Does that help or have I misunderstood your question?
This User Gave Thanks to hicksd8 For This Post:
# 3  
Old 09-01-2019
Sending me mails?
Who is "me"?

The crontab jobs send mails back to the owner, normally the output of the script (if there was any).
# 4  
Old 09-01-2019
Hello MadeInGermany,
root@hostname was submitting email.
I uninstalled some softwares which are not in use anymore and removed messaging softwares like mail,mailx,


Kind regards
Boris
# 5  
Old 09-10-2019
Tip: ptree for linux

Please safe the following script as "/usr/local/bin/ptree", and make it executable.
Code:
#!/bin/sh
# Solaris style ptree

[ -x /usr/bin/ptree ] && exec /usr/bin/ptree "$@"

PATH=/bin:/usr/bin:/usr/sbin:/sbin
export PATH

case $1 in
-*)
 echo "
Usage: ptree [ PID | USER ]
Print process tree
 PID : extract branch for this process
 USER : filter for this (existing) user
 USER PID : do both
"
 exit
;;
*[!0-9]*)
 psopt="-u $1"
 shift
;;
*)
 psopt="-e"
esac
psopt="$psopt -H -o pid= -o args="

if [ -z "$1" ]; then
 ps $psopt
 exit
fi

#some effort to add less to the ps list
tmp=/tmp/ptree.$$
trap 'rm -f $tmp' 0 HUP INT TERM
ps $psopt >$tmp
<$tmp awk '
{ ci=index(substr($0,6),$2); o[ci]=$0 }
ci>s[a] { s[++a]=ci }
$1==pid {
 for(i=1;i<=a;i++) {
  si=s[i]; if(si<=ci) print o[si]
 }
 walkdown=ci
 next
}
ci<=walkdown { exit }
walkdown!=0 { print }
' pid="$1"

Then put the following as one of the first commands into your "ban.sh" script:
Code:
/usr/local/bin/ptree $$ >>/tmp/ban.sh.ptree.out

Now, in /tmp/ban.sh.ptree.out you can see which processes (and parent processes) ran your "ban.sh".
This User Gave Thanks to MadeInGermany For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Detect and run command upon mouse movement

I am trying to find a way to run a command upon any movement of a mouse. The 1st statement shows the mouse co-ordinates. So it can detect mouse movement. xinput test 9 First list input devices: $ xinput list If possible, I would like to use it in a bash script. (2 Replies)
Discussion started by: drew77
2 Replies

2. Shell Programming and Scripting

Using grep command to detect presence of script run

i have this line of code on a korn shell script to detect the presence of script run: ISRUNNING=`ps -eaf -o args | grep -i sfs_load_file.ksh | grep -v grep | wc -l` sometimes this returns either 1, 2, or 3. when it returns 2 or 3 that tells us that there are more than 1 script of... (8 Replies)
Discussion started by: wtolentino
8 Replies

3. Shell Programming and Scripting

How to detect Hanged process in shell script?

I have to check daily 20 processes each day. The names are like Network1 Network2 Network3 ....... Network20. There is built in utility for doing this. Following is the command to check a single network process. check_process_status 1 If we want to check the status of Network2 then the... (6 Replies)
Discussion started by: Nakul_sh
6 Replies

4. Shell Programming and Scripting

How to detect that foreground process is waiting for input?

Hi, I have to create a script (ksh or perl) that starts certain number of parallel jobs (another scripts), each of them runs as a foreground process in a separate session. Plus I start monitoring job that has to determine if any of those scripts is expecting input from operator, and switch to... (4 Replies)
Discussion started by: andyh80
4 Replies

5. Shell Programming and Scripting

How to run a particular process

Hi I have a perl script where i created 3 nmap scans and the results will output to a text file. But when i run the code the first ip address gets scanned then the others after, but i want to be able to choose which ip address to scan. Here is my code: (`nmap -v -r 99.xxx.xxx -p... (0 Replies)
Discussion started by: kingbp
0 Replies

6. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

7. UNIX for Dummies Questions & Answers

Run a detached process

Hey guys, Just wondering is there anyway that I would be able to run a detached process that would continue to run regardless of me being logged into the linux host? (4 Replies)
Discussion started by: killaram
4 Replies

8. UNIX for Dummies Questions & Answers

Check the process before run or not

Dear all, I am writing a shell that check the java application already run. If it is not run before it will run next commands. ps -ef | grep java Thank you :) (3 Replies)
Discussion started by: mr_bold
3 Replies

9. UNIX for Dummies Questions & Answers

How can I run a process under particular ID?

I have a script that needs to run under ID say "xyz". the way I do normally is to "su" to the id, enter the password of "xyz" and run the process. However, is there any way run the process under "xyz" without "su" to the ID. A person with root access would be able to run any process under any ID as... (4 Replies)
Discussion started by: ucbus
4 Replies

10. Shell Programming and Scripting

How to detect process

Dear Sir, Now I use oracle database on AIX server and found some user use iligal program such as development tool logon to my database. I want to detect the process of illegal program and kill it. Could you please suggest me to make detect process. Thank you very much Pkanonwe. (2 Replies)
Discussion started by: pkanonwe
2 Replies
Login or Register to Ask a Question