Visit The New, Modern Unix Linux Community


Shell script to find the GB files in /tmp directory in remote server


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to find the GB files in /tmp directory in remote server
# 1  
RedHat Shell script to find the GB files in /tmp directory in remote server

Hi,
i need help on shell scripting.

Main intention of the script is
step 1: ssh to remote server
Step 2: cd /tmp in remote server
Step 3: in tmp i want to grep only files and directories which are in GB sizes

All the servers list file is - tmpsrv.txt

Code:
 vi tmpsrv.txt
 in001srv1
in001srv2
in001srv3
-
-
in001srv15

As of now i prepared the script as follows
Code:
 #!/bin/bash
while read line
do
 ssh -n $line "cd /tmp; du -sh * | awk '{ $1 ~ /[0-9]G }' "
done << tmpsrv.txt

/tmp sample data is
Code:
 1G     xxxx
2.2M   cdj
4.3G   jkth
5.2G   oiuf

Error :::
if i run my above code, i am getting the error like
Code:
  
 awk:  ~ [0-9]G/ 
awk:  ^ syntax error
awk:  ~ [0-9]G/ 
awk:        ^ syntax error
awk:  ~ [0-9]G/ 
awk:  ^ syntax error

but if i run the command alone du -sh * | awk '{ $1 ~ /[0-9]G }, i am getting the result as expected.

please guide me to correct the code.
Moderator's Comments:
Mod Comment CODE tags are needed for all sample input, sample output, and sample code.

Last edited by Don Cragun; 05-27-2015 at 02:38 AM.. Reason: Add CODE and ICODE tags.
# 2  
Hello kumar85shiv,

Could you please change code awk '{ $1 ~ /[0-9]G }' " to awk '{if($1 ~ /[0-9]G/){print} }' " and let us know if this helps. Here I am considering that your ssh is working as expected.


Thanks,
R. Singh

Last edited by RavinderSingh13; 05-27-2015 at 02:36 AM.. Reason: changed a bit
# 3  
Hi

I changed as you suggested, but its giving the same error.

Code:
 awk: { ~ [0-9]G/ }
awk:   ^ syntax error
awk: { ~ [0-9]G/ }
awk:         ^ syntax error
awk: { ~ [0-9]G/ }
awk:   ^ syntax error
awk: { ~ [0-9]G/ }
awk:         ^ syntax error
awk: { ~ [0-9]G/ }
awk:   ^ syntax error

---------- Post updated at 12:29 AM ---------- Previous update was at 12:27 AM ----------

please find the below error

Code:
 awk: { ~ /[0-9]G/ }
awk:   ^ syntax error
awk: { ~ /[0-9]G/ }
awk:   ^ syntax error
awk: { ~ /[0-9]G/ }
awk:   ^ syntax error
awk: { ~ /[0-9]G/ }
awk:   ^ syntax error


Last edited by Don Cragun; 05-28-2015 at 01:20 AM.. Reason: Add missing CODE tags again.
# 4  
hi ,

can you try like awk '\$1 ~/[0-9]G/ { print $0 }'

venky
Moderator's Comments:
Mod Comment Please use CODE (or ICODE) tags when posting sample input, output, and code.

Last edited by Don Cragun; 05-27-2015 at 03:33 AM.. Reason: Add ICODE tags.
# 5  
Hi Venky,

I changed as you suggested.

But, there is no out put from the script.

here with -x option

Code:
 bash -x kacey.sh 
 + read line
+ ssh -n in001srv1 'cd /tmp; du -sh * | awk '\''{ $1~ /[0-9]G/ }'\'' '
+ read line
+ ssh -n in001srv2 'cd /tmp; du -sh * | awk '\''{ $1~ /[0-9]G/ }'\'' '
+ read line
+ ssh -n in001srv3 'cd /tmp; du -sh * | awk '\''{ $1~ /[0-9]G/ }'\'' '
+ read line
+ ssh -n in001srv4 'cd /tmp; du -sh * | awk '\''{ $1~ /[0-9]G/ }'\'' '
+ read line

---------- Post updated at 12:49 AM ---------- Previous update was at 12:46 AM ----------

Code:
 awk: $1~ /[0-9]G/ { print ./kacey.sh }
awk:                      ^ syntax error
awk: $1~ /[0-9]G/ { print ./kacey.sh }
awk:                        ^ unterminated regexp
awk: cmd. line:1: $1~ /[0-9]G/ { print ./kacey.sh }
awk: cmd. line:1:                                  ^ unexpected newline or end of string
awk: $1~ /[0-9]G/ { print ./kacey.sh }
awk:                      ^ syntax error
awk: $1~ /[0-9]G/ { print ./kacey.sh }
awk:                        ^ unterminated regexp
awk: cmd. line:1: $1~ /[0-9]G/ { print ./kacey.sh }
awk: cmd. line:1:                                  ^ unexpected newline or end of string
awk: $1~ /[0-9]G/ { print ./kacey.sh }
awk:                      ^ syntax error
awk: $1~ /[0-9]G/ { print ./kacey.sh }
awk:                        ^ unterminated regexp
awk: cmd. line:1: $1~ /[0-9]G/ { print ./kacey.sh }
awk: cmd. line:1:                                  ^ unexpected newline or end of string
awk: $1~ /[0-9]G/ { print ./kacey.sh }
awk:                      ^ syntax error
awk: $1~ /[0-9]G/ { print ./kacey.sh }
awk:                        ^ unterminated regexp
awk: cmd. line:1: $1~ /[0-9]G/ { print ./kacey.sh }
awk: cmd. line:1:                                  ^ unexpected newline or end of string

# 6  
Hi,

please try

ssh -n $line "du -sh /tmp/* | awk '\$1 ~ /[0-9]G/{print $0}'"

venky
# 7  
Hi venky ,

I changed the script as like this

Code:
 #!/bin/bash 
while read line
do
        ssh -n $line "du -sh /tmp/* | awk '\$1 ~ /[0-9]G/{print $0}'"
done < tmpsrv.txt

but getting the error like below.

Code:
 ./kacey.sh}
awk:                     ^ syntax error
awk: $1 ~ /[0-9]G/{print ./kacey.sh}
awk:                       ^ unterminated regexp
awk: cmd. line:1: $1 ~ /[0-9]G/{print ./kacey.sh}
awk: cmd. line:1:                                ^ unexpected newline or end of string
awk: $1 ~ /[0-9]G/{print ./kacey.sh}
awk:                     ^ syntax error
awk: $1 ~ /[0-9]G/{print ./kacey.sh}
awk:                       ^ unterminated regexp
awk: cmd. line:1: $1 ~ /[0-9]G/{print ./kacey.sh}
awk: cmd. line:1:                                ^ unexpected newline or end of string
awk: $1 ~ /[0-9]G/{print ./kacey.sh}
awk:                     ^ syntax error
awk: $1 ~ /[0-9]G/{print ./kacey.sh}
awk:                       ^ unterminated regexp
awk: cmd. line:1: $1 ~ /[0-9]G/{print ./kacey.sh}
awk: cmd. line:1:                                ^ unexpected newline or end of string
awk: $1 ~ /[0-9]G/{print ./kacey.sh}
awk:                     ^ syntax error
awk: $1 ~ /[0-9]G/{print ./kacey.sh}
awk:                       ^ unterminated regexp
awk: cmd. line:1: $1 ~ /[0-9]G/{print ./kacey.sh}
awk: cmd. line:1:                                ^ unexpected newline or end of string


Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #793
Difficulty: Easy
The base-2 numeral system is a positional notation with a radix of 3.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script connect to remote server, not find files and exit only from remote server, but not from scrip

I have a script, which connecting to remote server and first checks, if the files are there by timestamp. If not I want the script exit without error. Below is a code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly;... (3 Replies)
Discussion started by: digioleg54
3 Replies

2. Shell Programming and Scripting

Error when connecting to remote server to find files with timestamp today's day

I am connecting to remote server and try to check if files with timestamp as Today's day are on the directory. Below is my code TARFILE=${NAME}.tar TARGZFILE=${NAME}.tar.gz ssh ${DESTSERVNAME} 'cd /export/home/iciprod/download/let/monthly; Today=`date +%Y%m%d`; if ;then echo "We... (1 Reply)
Discussion started by: digioleg54
1 Replies

3. Shell Programming and Scripting

How can I check, if on remote server directory is empty or have files?

I have a script, which is supposed to run 1 day of the month, connect to remote server certain directory, find files, tar the, and copy find . -ctime -1 | tar -cvf transfer_dmz_start_monthly.tar *${Today}*.*; if then echo "Cannot create a tar file, the terminated... (2 Replies)
Discussion started by: digioleg54
2 Replies

4. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

5. Shell Programming and Scripting

Shell script to find and replace contents of files in directory

Hi all This is my first post. Please bear with me with all my mistakes. I started learning shell since couple of days now and this might be quite basic for all, i want to search for files in a directory containing specific string and replace it with new string. The code i wrote is quite bulky... (2 Replies)
Discussion started by: theprogrammer
2 Replies

6. Shell Programming and Scripting

FTP files from different directory from remote server to one directory in local

Hi All, I want to search for .log files from folders and sub folders in remote server and FTP them to one particular folder in the local machine. I dont want to copy the entire directory tree structure, just have to take all the .log files from all the folders by doing a recursive search from the... (3 Replies)
Discussion started by: dassv
3 Replies

7. Shell Programming and Scripting

Need script to remove millions of tmp files in /html/cache/ directory

Hello, I just saw that on my vps (centOS) my oscommerce with a seo script has created millions of tmp files inside the /html/cache/ directory. I would need to remove all those files (millions), I tried via shell but the vps loads goes to very high and it hangs, is there some way to do a... (7 Replies)
Discussion started by: andymc1
7 Replies

8. UNIX for Dummies Questions & Answers

Long listing of files using find command on remote server via SSH

Hi , I am trying to find some files on a remote machine using the find command. >ssh -q atukuri@remotehostname find /home/atukuri/ -name abc.txt /home/atukuri/abc.txt The above command works fine and lists the file, but if I want to do a long listing of files (ls -l) its not working . ... (2 Replies)
Discussion started by: atukuri
2 Replies

9. Shell Programming and Scripting

shell script to find and copy the files creted in the year 2006 to another directory

Hi All, I am new to UNIX. I will be thankful if some one helps me. I have to write a shell script for one of the requirement. I have files created from Jan 2006 to March 2008. My requirement is to write a script in such a way that 1) To find and copy(not Moving) the files created in the... (2 Replies)
Discussion started by: manas6
2 Replies

10. Shell Programming and Scripting

Find files not accessed on a remote server and delete - Help!

Hi Guys, I am currently working on a script to find all the files that have not been accessed for the past 2 years. This, i guess has been discussed n number of times in this forum. Now, my requirement is to find all the files in the remote windows server. I have it mounted in unix. I was... (1 Reply)
Discussion started by: bond_bhai
1 Replies

Featured Tech Videos