- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Shell script help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 08:04 PM
07-12-2004 08:04 PM
I've been tasked with creating a unix shell script that will select the latest created file and ftp it to another i.e. the file is currently generated every 12 hours (at 00:00 & 12:00) and 7 days worth are kept at any one time. Therefore the files in the directory are as follows:
-rw-rw-rw- 1 nortel nortel 12423 Jul 5 00:03 GSIT20040705000002.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 5 12:03 GSIT20040705120004.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 6 00:03 GSIT20040706000002.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 6 12:03 GSIT20040706120004.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 7 00:03 GSIT20040707000003.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 7 12:03 GSIT20040707120005.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 8 00:03 GSIT20040708000003.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 8 12:03 GSIT20040708120005.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 9 00:03 GSIT20040709000003.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 9 12:03 GSIT20040709120002.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 10 00:03 GSIT20040710000002.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 10 12:03 GSIT20040710120005.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 11 00:03 GSIT20040711000002.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 11 12:03 GSIT20040711120005.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 12 00:03 GSIT20040712000002.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 12 12:03 GSIT20040712120005.drf
-rw-rw-rw- 1 nortel nortel 12423 Jul 13 00:03 GSIT20040713000003.drf
Therefore what I need to do is at midnight after the file has been created I will need to select the latest file and ftp it to another server and at mid-day again I will have to perform the same task but with the latest file generated at midday etc, etc. As can be seen above the files are generated automatically and contain the date & time in the filename.
I'm a beginner at shell scripting and would greatly appreciate any help that can be provided.
Cheers
AK
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 08:23 PM
07-12-2004 08:23 PM
SolutionUse the system commands to find the newest file such as
dir=/home/steves/tmp
ls -1tr $dir|tail -n 1|while read line
do
file=$(find $dir -name $line)
echo $file
done
Put your dir where mine is and file is the newest one
http://www.shelldorado.com/
Is a good place for a learner
Steve Steel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 08:24 PM
07-12-2004 08:24 PM
Re: Shell script help
Since I dont know how you want your ftp, all I can do here is how to select your file:
ll -lt¦grep GSIT ¦ head -n 1
Good luck
Vi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 08:26 PM
07-12-2004 08:26 PM
Re: Shell script help
you could find out the latest file by using "tail -1" command
For example :
for i in `ls /
do
ftp $i ...
done
HTH
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 08:27 PM
07-12-2004 08:27 PM
Re: Shell script help
You should read "pipe" I will give a try with another char | and se if it displays correctly
All the best
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 08:30 PM
07-12-2004 08:30 PM
Re: Shell script help
Start again:
You wanted 1 file - the latest...
ll -lt | grep GSIT | head -n 1
There you are
All the best
Victor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 08:39 PM
07-12-2004 08:39 PM
Re: Shell script help
for i in `ls -t`
do
echo $i
# Other commands...
exit
done
sks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 08:41 PM
07-12-2004 08:41 PM
Re: Shell script help
Cheers
Andy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 08:49 PM
07-12-2004 08:49 PM
Re: Shell script help
YOu can schedule the script to run twice a day through cron job. i.e
00 00,12 * * * /path/script_name > output_log
and the script_name can contain the following line.
Initiall touch a temp_file. Then find the GSIT file that was newer than the touched file as.
find /path -name *GSIT* -newer touched_temp_file |cpio...........
and after the copy to thebother server
remove the touch_temp_file
touch temp_file again.
So that next time the GSIT* file generated will be newer than the touched file. And you have this files generated only twice a day at 00:00 and 12:00. So when the cron job copies the file and touched the temp file, next GSIT file will be newer than the touched file.
I hope this helps You.
Indira A
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 09:10 PM
07-12-2004 09:10 PM
Re: Shell script help
Just to participate,
Similar to Victor but this one will only return the Filename:
# ls -t | head -n 1
You can even assign the name to an variable and write a script to FTP the file using that varible.
# var1=`ls -t | head -n 1`
(remember these are back quotes)
Hope that helps.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2004 09:28 PM
07-12-2004 09:28 PM
Re: Shell script help
Get the recent created file with a line script as,
#script.ksh
# usage:
filename=$(ls -l | grep -v '^total*' | sort -r | head -1)
username=$1
passwd=$2
location=$3
ftp -i -n $server <<-EOF 2>/dev/null
user $usename $passwd
put $filename $location
bye
EOF
# total message will come if we use ll or ls -l
You can use rcp too instead of ftp for this. make "+" entry in $HOME/.rhosts file on two server
Simulate this in a cron job at your required time (at 00:00 & 12:00)
Regards,
Muthukumar.
Muthukumar.