Computing.Net > Forums > Unix > shell script to find & get the specific file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

shell script to find & get the specific file

Reply to Message Icon

Name: vinayak_C21
Date: June 19, 2009 at 02:33:05 Pacific
OS: AIX
Subcategory: General
Comment:

Requirement : need help to write a script which can get the reports for last 7 days, tar it, zip it and send it vai mail...

I have wriiten the script for this which finds, tar, compress and mail the reports but it works from the same server on which the reports are generated - the pord server. We have to run the script on dev server to get the files from prod to dev and then my script can work.. now the issue is .. how to get those reports generated for last 7 days from the prod server... your help would be appreciated...



Sponsored Link
Ads by Google

Response Number 1
Name: vinayak_C21
Date: June 19, 2009 at 03:02:04 Pacific
Reply:

Guys .. please help...


0

Response Number 2
Name: David Perry
Date: June 19, 2009 at 06:17:59 Pacific
Reply:

Do you need to copy files to the dev server or can you mount a share and do it?


0

Response Number 3
Name: vinayak_C21
Date: June 19, 2009 at 07:20:18 Pacific
Reply:

Hi david,

Thanks for the response!

I have to copy those reports ( for last 7 days and name starting with "test*" ) to dev servers and then i have to send those by mails after compressing it.. the report has the date in it's name.

I have to perform all these operations from Dev server...


0

Response Number 4
Name: David Perry
Date: June 19, 2009 at 09:30:21 Pacific
Reply:

You can copy files with among other things, dependent on your network policies,

ftp, scp, sftp, rsync, mounting a share and cp

find /directory -name "PATTERN" -mtime -7 -exec rsync -av {} servername::module/

as an example.


0

Response Number 5
Name: psiva_unix
Date: June 25, 2009 at 11:43:31 Pacific
Reply:

Hi Vinayak,

You can use the atime command and get the file for last seven days from the current date and then zip it and send it through mail
find <dir_path> -type f -name "*.txt*" -atime +7 -exec ls -l { } \; > /tmp/files.txt
gzip /tmp/files.txt
uuencode /tmp/files.txt.z /tmp/files.txt.z | mailx -s "7day files" "yourmail_id@gmail.com

rm /tmp/files.txt
rm /tmp/files.txt.z
exit 0


0

Related Posts

See More



Response Number 6
Name: vinayak_C21
Date: July 3, 2009 at 00:34:11 Pacific
Reply:

Hey Siva .. Thanks for the reply.. but the script that u suggested works fine on the machine on which the reports are generated... i have to run the script on remote machine to get thses reports..

Explaination : I have to run the script on host A to copy the reports generated for last 7 days (Name starting with ABC*) from the host B... I have only FTP access to host B.. once the required reports are copied from host B to Host A... i can then execute your script on host A... Hope it is clear now.. Will appreciate your help..thanks!


0

Response Number 7
Name: vinayak_C21
Date: July 7, 2009 at 08:18:18 Pacific
Reply:

Guys,

I have written the script to achieve the goal, i dont see any error in the script but dont know why script does not execute properly...

#!/usr/bin/ksh

### Running this script on host100 from the directory /app/script/Util/LoginRPT.sh

rptdir=/app/report
tmp=$rptdir/tmp.cfg
rpt=$rptdir/rpt.cfg

cat /dev/null > $tmp
ftp -ivn host123 <<EOF
user u_name passwd
cd /app/out
bin
ls "-rt ." $tmp ## This gives the list sorted by time of all files in Out dir of host123
bye
EOF

cat $tmp | grep -i LogIn | tail -7 > $rpt ## to get the latest 7 login reports in the rpt.cfg file

cat $rpt | while read line
do
ftp -ivn host123 <<EOF
user u_name passwd
cd /app/out
lcd $rptdir
bin
mget $line
quit
EOF
done;
cd $rptdir
tar -cvf LogInReport.tar -L rpt.cfg
gzip -9 LogInReport.tar
uuencode LogInReport.tar.gz LogInReport.tar.gz | mailx -r 'APP' -s "LogIn report for last week" abc@xyz.com cba@xyz.com

#--------end of script--------#

It quits once the first ftp is executed.. after bye it comes out of the script..
Please help


0

Response Number 8
Name: nails
Date: July 7, 2009 at 13:57:49 Pacific
Reply:

Try placing the ftp command in it's own subshell:

cat $rpt | while read line
 do
   # parenthesis placing the ftp in own subshell:
   (   
   ftp -ivn host123 <<EOF
   user u_name passwd
   cd /app/out
   lcd $rptdir
   bin
   mget $line 
   quit
   EOF
)

done;

0

Response Number 9
Name: vinayak_C21
Date: July 8, 2009 at 05:57:40 Pacific
Reply:

Hi Nail..thanks for the reply..
Please take a look at my script again
.. i am doing ftp twice and the issue i m facing is in first ftp... the script exits after finishing the first ftp part..

Help would be really appreciated..thanks!


0

Response Number 10
Name: vinayak_C21
Date: July 8, 2009 at 07:02:47 Pacific
Reply:

Hey..Strange but Script worked...

tried by rewriting the script again.. and it is working fine now..

Thanks all for all your help...


0

Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: shell script to find & get the specific file

shell script to check for a file on www.computing.net/answers/unix/shell-script-to-check-for-a-file-on/3714.html

Please help w/ shell script ASAP www.computing.net/answers/unix/please-help-w-shell-script-asap/4323.html

Shell script to find files www.computing.net/answers/unix/shell-script-to-find-files/5440.html