Sponsored Content
Full Discussion: pid.cleanup script.
Top Forums Shell Programming and Scripting pid.cleanup script. Post 302500273 by sajid.shah on Monday 28th of February 2011 06:44:43 AM
Old 02-28-2011
pid.cleanup script.

Hi guys!

I have a directory in the production environment from which i have to delete files older then 40 minutes with .pid extention. I wrote a script below for the purpose.

Code:
#!/bin/bash
#
# Script to delete specific file older than N minutes.
# OLDERTHAN="40" #40 minutes

FOLDER="home/optima/pids/"
PID="*.pid"
OLDERTHAN="40"
if [ -e ${FOLDER}/${PID} ]
then
     ls_time=`ls -l ${FOLDER}/$PID`
     pid_h=`echo $ls_time | cut -d\ -f 8 | cut -d\: -f 1`
     pid_m=`echo $ls_time | cut -d\ -f 8 | cut -d\: -f 2`
     echo pid time=$pid_h:$pid_m
     let pid_time=(10#$pid_h*60)+10#$pid_m
     curr_h=`date | cut -d\ -f 4 | cut -d\: -f 1`
     curr_m=`date | cut -d\ -f 4 | cut -d\: -f 2`
     let curr_time=(10#$curr_h*60)+10#$curr_m
     echo curr_time=`date | cut -d\ -f 4`
     let diff=10#$curr_time-10#$pid_time
     #echo pid_time=$pid_time
     #echo curr_time=$curr_time
     echo diff=$diff minutes
     if [ $diff -ge $OLDERTHAN ]
     then
          echo "${PID} is older than $OLDERTHAN minutes"
          echo "Deleting ${PID}..."
          rm -f ${FOLDER}/${PID}
     else
          echo -e "${PID} is not older than $OLDERTHAN minutes"
     fi
else
     echo -e "${PID} not found."
fi

I created a test pid in /home/somefolder/pids to check if the script will delete old pids or not. I ran it & it showed the following result “*.pid not found.” Any advice?

Code:
# ls -ltr
total 96
-rw-r----- 1 root sys 0 Feb 28 09:00 test.pid
-rwxr-xr-x 1 root sys 15 Feb 28 11:52 optimamd_opx_LOD_GEN_110_00111010L.pid
-rwxr-xr-x 1 root sys 15 Feb 28 11:52 optimamd_opx_LOD_GEN_110_001110107.pid
-rwxr-xr-x 1 root sys 15 Feb 28 11:52 optimamd_opx_LOD_GEN_110_001110109.pid
-rwxr-xr-x 1 root sys 16 Feb 28 11:52 optimamd_opx_LOD_GEN_110_00111010H.pid
-rwxr-xr-x 1 root sys 15 Feb 28 11:52 optimamd_opx_LOD_GEN_110_00111009A.pid
-rwxr-xr-x 1 root sys 15 Feb 28 11:52 optimamd_opx_LOD_GEN_110_001110106.pid
#
 
/home/optima/run
 
-rwxrwxrwx 1 optima dba 1716 Jun 2 2010 NSN_MGWtest_DAP.sh
-rwxrwxrwx 1 optima dba 2828 Jul 7 2010 RunValidators_HUAWEI_BSC6000.sh.orig
-rwxrwxrwx 1 optima dba 5482 Jul 7 2010 NSN_MSS_DAP.sh
-rwxrwxrwx 1 optima dba 1729 Jul 7 2010 NSN_MGW_DAP.sh
-rwxrwxrwx 1 optima dba 244 Jul 7 2010 Run_FTP.sh
-rwxrwxrwx 1 optima dba 1914 Jul 7 2010 NSN_MGW_VAL.sh
-rwxrwxrwx 1 optima dba 6013 Jul 7 2010 NSN_MSS_VAL.sh
-rwxrwxrwx 1 optima dba 5138 Jul 9 2010 NSN_MSS_loader.sh
-rwxrwxrwx 1 optima dba 1715 Jul 9 2010 NSN_MGW_loader.sh
-rwxrwxrwx 1 optima dba 1460 Jul 10 2010 MOTOROLA_BSS_VALIDATOR.sh
-rwxrwxrwx 1 optima dba 6100 Oct 11 08:37 RunLoaders_HUAWEI_BSC6000.sh
-rwxrwxrwx 1 optima dba 2828 Oct 18 12:40 RunValidators_HUAWEI_BSC6000.sh
-rwxrwxrwx 1 optima dba 945 Nov 29 16:27 MOTOROLA_BSS_CMB.sh
-rwxrwxrwx 1 optima dba 2120 Dec 6 11:39 MOTOROLA_BSS_LOADERS.sh
-rwxrwxrwx 1 optima dba 228 Jan 10 11:31 OLD_RunProcessMonitor_004.sh
-rwx------ 1 root sys 252 Jan 19 12:34 Neighbour_single.sh
-rwx------ 1 root sys 228 Jan 26 12:07 RunProcessMonitor_004.sh
-rwxrwxrwx 1 root sys 957 Feb 28 11:39 pid_cleanup.sh
# ./pid_cleanup.sh
*.pid not found.


will changing
Code:
PID="*.pid"

to
Code:
PID="*pid* *.pid*".

help?

---------- Post updated at 06:44 AM ---------- Previous update was at 05:19 AM ----------

I replaced PID=”*.pid” with PID="*pid* *.pid*" and ran the script and got the below result. Kindly advice.
Code:
# ./pid_cleanup.sh
./pid_cleanup.sh: script:  not found.
./pid_cleanup.sh[10]: Syntax error at line 16 : `(' is not expected.
#

Moderator's Comments:
Mod Comment Please use code tags also in updates. Also please refrain from overly use of font formatting since it is awful to remove when editing your post, thanks. It would be also helpful if you'd use indention when posting your scripts as well.

Last edited by zaxxon; 02-28-2011 at 08:08 AM.. Reason: code tags, indention etc.
 

10 More Discussions You Might Find Interesting

1. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies

2. UNIX for Dummies Questions & Answers

Session PID & socket connection pid

1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection? 2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
Discussion started by: pcx26
1 Replies

3. Shell Programming and Scripting

awk/sed/ksh script to cleanup /etc/group file

Many of my servers' /etc/group file have many userid's that does not exist in /etc/passwd file and they need to be deleted. This happened due to manual manipulation of /etc/passwd files. I need to do this for 40 servers. Can anyone help me in achieving this? Even reducing a step or two will be... (6 Replies)
Discussion started by: pdtak
6 Replies

4. Shell Programming and Scripting

User Cleanup Script

Hi Guys, I've got an system setup to act as an sftp server. I have a script that allows me to create chroot users running a custom shell within their home directory, it also creates a subdirectory that they can write into. I'm trying to write a script (that I can cron at a later date) that checks... (3 Replies)
Discussion started by: King_Brucie
3 Replies

5. Shell Programming and Scripting

Cleanup script

Hi! I would like to write a script which remove some files, all beginning with the same prefix : prefix.1 doc/prefix.2 ../prefix.3 etc. So, I would create a file and chmod it executable. But I dont know how to pass a variable to a script. I would like to write something like ... (2 Replies)
Discussion started by: tipi
2 Replies

6. Shell Programming and Scripting

Suggestions/cleanup Bash script

Hello, beginner bash scripter here.. I was able to write a script and it works just fine. I'm just wondering if someone could chime in or any suggestions to make it cleaner or tighter so to speak. I have a disk to disk backup solution which uses 250GB disks. When one gets full I just po in a new... (7 Replies)
Discussion started by: woodson2
7 Replies

7. Shell Programming and Scripting

Mail cleanup from ksh script, keeping 50 most recent msgs

I found some posts describing how to completely clean out a mailbox in Unix/Linux. But I want to keep the 50 most recent messages. Any ideas out there? Thanks! (3 Replies)
Discussion started by: OPTIMUS_prime
3 Replies

8. UNIX for Advanced & Expert Users

Table Cleanup Script

I needed some help with a script to fetch and delete all records prior to 3 days from now connecting to sybase from sunos. I wrote the following script but not working..can someone please guide me with my code. Thanks #!/bin/ksh ##GET PREVIOUS DAY DATE dt=`date | awk... (3 Replies)
Discussion started by: moe458
3 Replies

9. Shell Programming and Scripting

Suggestion with script to cleanup

I need help with sed and awk scripts to search for Symmetrix ID=000090009902 and then grep its child disk devices associated to the dead paths and display them only, so that those dead devices can be removed. test01:/#powermt display dev=all Pseudo name=hdiskpower0 Symmetrix ID=000090009902... (0 Replies)
Discussion started by: aix_admin_007
0 Replies

10. Shell Programming and Scripting

UNIX script for cleanup

Hello, I need some help from unix guru's here..I am looking for some advanced level script to cleanup the directories and files from specific directories under a file system.. The folders are created under /opt/modules And under modules, there are multiple subfolders with the application... (6 Replies)
Discussion started by: mb525
6 Replies
All times are GMT -4. The time now is 09:13 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy