create a periodic execution of a script?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers create a periodic execution of a script?
# 1  
Old 04-17-2002
Data create a periodic execution of a script?

Hello every body
goal: create a script that control periodicly ( every 30 min ) if a process is already actif.

How can I do that?

thanks
# 2  
Old 04-17-2002
1- create a simple Script ver_proc.sh (in a apropiate directory example /usr/local/scripts/varios or /usr/local/sbin/varios)
#!/bin/ksh
if [ $# -ne 1 ]
then
echo "Usage: $0 <proc_name>"
fi
PROC_NAME=$1
DAY=`date +"%Y%m%d"`
TIME=`date +"%Y/%m/%d %H:%M"`
CURR_SCRIPT=$0
if [ ! -d /var/log/$DAY ]
then
mkdir /var/log/$DAY
chmod 0755 /var/log/$DAY
fi
OUT=/var/log/$DAY/ps_$DAY.txt
if [ `ps -ef |grep $PROC_NAME |grep -v $CURR_SCRIPT |grep -v grep |wc -l ` -eq 1 ]
then
echo "$TIME `/usr/ucb/ps vax |grep $PROC_NAME |grep -v $CURR_SCRIPT |grep -v grep`" >> $OUT
else
ps -ef |grep $PROC_NAME |grep -v $CURR_SCRIPT |grep -v grep | while read linea
do
TIME=`date +"%Y/%m/%d %H:%M"`
echo "$TIME $linea" >> $OUT
done
fi

exit 0

2- chmod 0755 /usr/local/scripts/varios/ver_proc.sh

3- create a cron Job.
EDITOR=/usr/bin/vi ; export EDITOR
cron -e
# add the following line
00,30 * * * * [ -x /usr/local/scripts/varios/ver_proc.sh ] \
/usr/local/scripts/varios/ver_proc.sh <proc_name>

4- Modify the script at your flavor

Last edited by hugo_perez; 04-17-2002 at 11:59 AM..
# 3  
Old 04-17-2002
TEACH don't GIVE

I would swear that this is a typical homework question. Could someone please close this post?

FYI to everyone. Especially newbies!

Please ask for more information about what the user is trying to do before shooting your wad with the complete answer.

Remember that oldie but goodie? Not mine but a great lesson.

GIVE a man a fish and feed him for a day.
TEACH a man to fish and feed him for a lifetime.


Smilie Smilie
# 4  
Old 04-17-2002
Sound like a reasonable request Smilie
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Vuejs Periodic Table by Kadin Zhang

Was working on Vue.js and stumbled upon this beautiful Vue project by Kadin Zhang Periodicity is a dynamic periodic table built with Vue.js that animates and graphs data to aid the visualization of chemical concepts. The code is available on GitHub (2 Replies)
Discussion started by: Neo
2 Replies

2. Shell Programming and Scripting

Create an execution logic of script

Hi All, I have a file which is in below shape. Script should run and pick 1 and 2nd line and first line value store in A variable only numeric and 2nd line value should store in B variable only numeric. Then I have command which will check the value of these two tickets if both is having the... (1 Reply)
Discussion started by: anuragpgtgerman
1 Replies

3. Shell Programming and Scripting

awk Script: removing periodic boundaries

SOLVED, thank you! Edit2: Good news everyone, I managed to get it down to a "simple" problem, but I still have some syntax issues. Here is the code which troubles me: awk 'BEGIN{x2=0;x1=0;crit=0;} $1 < 1000000 {x2=$4; diffx=x2-x1; x1=x2; diffx > 3.6 ? {crit=1} : {crit=0};... (2 Replies)
Discussion started by: Consti
2 Replies

4. Ubuntu

Wireless periodic drops - Ubuntu 12.10

Ubuntu wireless has been fine until fresh installation of 12.10. Now, I have periodic drops of the wireless. I can manually disconnect and then reconnect to get the service back. Sometimes, I am unable to disconnect. When this happens, I have to log off and then on again. (0 Replies)
Discussion started by: jamarsh
0 Replies

5. Programming

Periodic thread with clock_nanosleep

Hi I have a periodic task (with the highest priority) which I away every X nano-second. I am using the function clock_nanosleep with REAL_TIME timer. when I wake up, I versify that I was awake on time, and check if the delta between the last time I get to sleep and the current time is X... (4 Replies)
Discussion started by: laro1983
4 Replies

6. UNIX for Dummies Questions & Answers

Remove 1st character in periodic lines

Hi, I have a file that looks like this, the unity of information is composed of four lines, and these extends for millions. My objective is to remove the highligthed "T". How to attack this? This character is always constant in type "T" and position "1st" but the rest of the line is... (7 Replies)
Discussion started by: sargotrons
7 Replies

7. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

8. Cybersecurity

Periodic check of user password strength

I need to periodically run a check on the passwords of the users (Redhat 5.0) to verify that all passwords meet minimal standards. I remember seeing a script years ago that grabbed the encrypted passwords from the file and checked if they matched any of the encrypted strings in another file, plus... (1 Reply)
Discussion started by: tlynnch
1 Replies

9. Shell Programming and Scripting

Tcsh periodic requires carriage return

Hello All, My first post on this forum. I am using cygwin to help me with some routine jobs on my laptop, with tcsh as my shell. I need to copy a set of files from one directory to a network drive every minute. So I have set tperiod = 1 alias periodic 'cp *.txt /cygdrive/z/Data' ... (0 Replies)
Discussion started by: OmniVision
0 Replies

10. Shell Programming and Scripting

How to create file execution in KSH shell

Dear all, I'm new in Unix system, I need help about how to create execution file. for example in my system i have file fg* when i open fg file i get : cmd='basename$0' $cmd "$@" how to create file like that (execution file) in KSH shell thank you for your help heru (4 Replies)
Discussion started by: heru_90
4 Replies
Login or Register to Ask a Question