Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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...

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...

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.

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.comrm /tmp/files.txt
rm /tmp/files.txt.z
exit 0

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!

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.cfgcat /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
EOFcat $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

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;

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!

Hey..Strange but Script worked...
tried by rewriting the script again.. and it is working fine now..
Thanks all for all your help...

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |