LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-10-2012, 10:47 PM   #1
arvindk.monu
LQ Newbie
 
Registered: Aug 2009
Posts: 22

Rep: Reputation: 0
Script compressing the files in a directory in numerous servers


Hello All,

I am looking for help,i wrote a shell script to check diskspace and if it reaches more than 70% usage it should compress automatically as shown below.

#!/bin/bash
ALERT=70
for serv in shldvgfas001 shldvgfas002 shldvgfas003 shldvgfas004 shldvgfas005 shldvgfas006 shldvgfas007 shldvgfas008 shldvgfas009 shldvgfas010 shldvgfas017 shldvgfas018 shldvgfas019 shldvgfas020 shldvgfas021 shldvgfas022 shldvgfas051 shldvgfas052 shldvgfas053 shldvgfas054
do
usep=$(ssh $serv df -H |grep var | awk '{ print $4}' |cut -d'%' -f1 2> /dev/null )

if [ ${usep:-0} -ge 100 ]
then
mail -s "var directory have 0 percentage of free space on $serv please have a look" arvindk.monu@gmail.com </dev/null
ssh $serv rm /var/tmp/*;

elif [ ${usep:-0} -ge $ALERT ]
then
mail -s "Core files are Running out of space on $serv" arvindk.monu@gmail.com </dev/null
ssh $serv bzip2 /var/tmp/*;

fi
done


when i am running it, it is giving me error "bzip2: Can't open input file /var/tmp/Efare.gfarest6.gfarest6_1.server9.native1: No such file or directory."

Please help urgently.

Last edited by arvindk.monu; 04-10-2012 at 10:48 PM.
 
Old 04-10-2012, 11:00 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
That looks like an error you would get from a temporary file that disappeared before bzip2 got to it. How does the rest of /var/tmp/ on the server in question look? Are the other files being bzipped like normal?
 
Old 04-10-2012, 11:11 PM   #3
arvindk.monu
LQ Newbie
 
Registered: Aug 2009
Posts: 22

Original Poster
Rep: Reputation: 0
Hello groll,

Yes other files can be bzipped like normal.when i am compressing files after logging in given individual servers i am able to compress but problem arise only when i am doing it in script,logically script is correct but i dont know where is the problem lies,Any help will be appreciated.
 
Old 04-11-2012, 03:37 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,243

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
Well my guess would be to discover what is creating the files in question? As you have stated, the premiss of the script is that the individual parts work at the
command line so it would stand to reason that when you connect to the servers via ssh it could be a file associated with the ssh'ing may be in there temporarily but on closure
of ssh, bzip is being left out in the cold.

I would also add that to combine grep, awk and cut is a complete waste. awk can quite happily perform all the tasks.
Also, you ssh into each server twice, I would have thought it better to ssh in once and perform the required tasks?
 
Old 04-17-2012, 12:07 PM   #5
arvindk.monu
LQ Newbie
 
Registered: Aug 2009
Posts: 22

Original Poster
Rep: Reputation: 0
my question is how to run a a script/command in each and every server in the loop by the way n this

grep var | awk '{ print $4}' |cut -d'%' -f1 in this grep is redundant i can do
awk '/var/{print $4}'|cut -d'%'
 
Old 04-17-2012, 12:40 PM   #6
lithos
Senior Member
 
Registered: Jan 2010
Location: SI : 45.9531, 15.4894
Distribution: CentOS, OpenNA/Trustix, testing desktop openSuse 12.1 /Cinnamon/KDE4.8
Posts: 1,144

Rep: Reputation: 217Reputation: 217Reputation: 217
Hi,

Can you try to use TAR instead of BZIP2:
Code:
elif [ ${usep:-0} -ge $ALERT ]
then
mail -s "Core files are Running out of space on $serv" arvindk.monu@gmail.com </dev/null
# ssh $serv bzip2 /var/tmp/*;
ssh $serv tar pcjRf archive-filename.tar.bz /var/tmp/
good luck
 
1 members found this post helpful.
Old 04-17-2012, 12:54 PM   #7
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 481

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by arvindk.monu View Post
ssh $serv bzip2 /var/tmp/*;
The wild card pattern in the above command is most likely expanded locally, on the server where the script is running, rather than on $serv. I'd suggest quoting the pattern to avoid this, as follows:
Code:
ssh $serv bzip2 "/var/tmp/*"
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
tar compressing in particular directory elerox Linux - Software 3 04-03-2011 09:15 PM
help with compressing a directory for backup Lleb_KCir Linux - Newbie 8 10-28-2005 03:52 AM
Compressing directory with bzip2 Haiyadragon Linux - Newbie 1 06-22-2005 06:13 PM
Script for compressing files older than one year Pengu010011 Linux - Newbie 2 10-26-2004 08:53 AM
File Systems and Numerous files per directory dman65 Linux - General 1 10-06-2003 05:32 PM


All times are GMT -5. The time now is 01:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration