Check space and run command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Check space and run command
# 1  
Old 02-24-2016
Check space and run command

Hey
i have problem with cut and print column
problem is i want to execute shell script to run df -h /tmp
if the result ( Use% ) was more than 50% , run rm -rf /tmp/*
any idea how cut the result of df -h /tmp ?
# 2  
Old 02-24-2016
Hello nimafire,

You haven't mentioned you O.S details into your post, so code which I am providing I tested in BASH, may help you in same.
Code:
USAGE=`df -hP /tmp | awk 'FNR>1{sub(/%/,X,$(NF-1));if($5+0 > 0){print $(NF-1)}}'`
if [[ $USAGE -gt 0 ]]
then
    echo "Removing the files from /tmp now...."
    rm -rf /tmp/*
else
    echo "/tmp have not filled more than 50% as of now."
fi

Thanks,
R. Singh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to check who run the command?

Dear Team, i need to know in linux if someone run the command in linux server where i can check on server . i need to know the below points who (user) when (date and time) what (command) regards, scriptors (1 Reply)
Discussion started by: scriptor
1 Replies

2. Linux

Filesystem / (root) run ouf of space

Good evening, I've got a question, in our production system there is an application called Intermediate which ftp service is the core to to send back and forth from/to diferent destinations Gradually FS / was ruuning out space and we took a long time to figure out what precesses were eating up... (9 Replies)
Discussion started by: alexcol
9 Replies

3. Shell Programming and Scripting

Script for telnet and run one command kill it and run another command using while loop

( sleep 3 echo ${LOGIN} sleep 2 echo ${PSWD} sleep 2 while read line do echo "$line" PID=$? sleep 2 kill -9 $PID done < temp sleep 5 echo "exit" ) | telnet ${HOST} while is executing only command and exits. (5 Replies)
Discussion started by: sooda
5 Replies

4. Shell Programming and Scripting

How to check if script is run via cron or manual=command line?

Hi all, I have a script that can be run via cron or via the command line. Is there any way that I can place something on the script to be able to distinguish/differentiate whether the script was run via a user in the command line or whether it was run from the cron? (3 Replies)
Discussion started by: newbie_01
3 Replies

5. Shell Programming and Scripting

Check if line has a space

Hi, I want to check if the given line from a text file has a spaces in between. if it does, then I want to add '"' double quotes at the beginning and end of the line. Otherwise leave the line as it is. For example, below is the sample content from my file. $cat file.txt test1 test2... (6 Replies)
Discussion started by: svajhala
6 Replies

6. Solaris

Disk space check

Hi, I have a question regarding finding free space on the disk of a solaris machine. Many mount points are available in my machine. Right now i am using df -b option to get the free disk space available. I have an assignment to check free space on the disk. I pass the directory as a... (6 Replies)
Discussion started by: raghu.amilineni
6 Replies

7. AIX

run which command to check the actual user

hi gurus, i have a question: when run which javac under a user account I got the following results: PROD DB Server: /usr/java14/bin/javac DR DB Server: /usr/java14/bin/javac DEV DB Server: /usr/java5_64/bin/javac The .profile in all environments are same. so how do know who is the... (1 Reply)
Discussion started by: lweegp
1 Replies

8. Shell Programming and Scripting

how to avoid space to run remotely

If I run the following command remotely after ssh than it works fine su - oracle -c "/oracle/product/102/db/bin/dbshut" But If I run the following command it doesn't work su - oracle -c "/oracle/product/102/db/bin/lsnrctl stop" Because I think there is a space is present between lsnrctl and... (1 Reply)
Discussion started by: madhusmita
1 Replies

9. Shell Programming and Scripting

check space !!!

The have written the below script :- ============================ SPACE=`bdf /DATA_TRANSFER|awk '{print $4}' |grep "%"` TEST="96%" if then echo "Continue ....." sleep 2 else echo " Current space for DATA_TRANSFER is less than 02 %" echo " Pls clear space and than continue ....."... (2 Replies)
Discussion started by: kamlesh_p
2 Replies

10. Filesystems, Disks and Memory

RUN OUT SPACE (Root)

Dear Buddies, Plz Help me out ,,,,,, the Unix Servers i m working on ,,,Somes times run out of space in root ,,,due the generation of a file named STA ....which causes the system to crash ,,,,, plz hlp me !!!!!!!!!!!!!!!!!!!!!! how to find out the file ....generation causes ...... ... (6 Replies)
Discussion started by: scorpiyanz
6 Replies
Login or Register to Ask a Question