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
10-25-2010 02:54 PM
10-25-2010 02:54 PM
Script
I have to create a script where I have to move a file name of type FILEXXX_XXX_XXXX.TXT_YYMMDDHHMM.gz from one directory to another directory and once moved, I want to gunzip the file and remove the timestamp.
Have to run it in KSH shell.
I am new to scripting ..Can anyone please suggest ASAP?
- Tags:
- gunzip
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2010 03:57 PM
10-25-2010 03:57 PM
Re: Script
srce=./test
dest=./test2
for file in $(ls $srce)
do
newf=$(echo $file | sed 's/\.TXT_.*\.gz//').TXT.gz
mv $srce/$file $dest/$newf
gunzip $dest/$newf
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2010 04:12 PM
10-25-2010 04:12 PM
Re: Script
I am very new to this.
I have this request to perform :
Move the file under
/u03/UBIDW/data/BART/FILE135_PI_TURNAWAYS.TXT_YYMMDDHHMM.gz to /u03/UBIDW/data/inbound -gunzipping the file and removing the _YYMMDDHHMM extension.
/u03/UBIDW/data/BART is the source
/u03/UBIDW/data/inbound is the destination.
File has a fixed value which is FILE135_PI_TURNAWAYS.TXT_YYMMDDHHMM.gz. It will always come on our server in this format.
1. When it will move to inbound, it should gunzip and remove the timestamp. That is the task which I need to perform...
Second thing is :
we already had scripts for such tasks. an example of that script is :
exec 1>>/oracle/EBAIX/files/inputs/xxtng/mis/logs/HKP_COM_AIX_EBW04.log 2>>/oracle/EBAIX/files/inputs/xxtng/mis/logs/HKP_COM_
AIX_EBW04.log
#csc_startmsg
STATUS=$1
filelist="$2"
#STATUS=SUCCESS
#filelist=FILE134_PI_RESERVATION_OR_STAY.TXT
#echo $STATUS
#echo $filelist
###############################################################################
# Begin the Main process
if [ "$STATUS" = "SUCCESS" ]
then
cd /u03/PBIDW/data/backup;
pattern="${filelist}[_,.]`date '+%y%m%d'`"
filename=`ls -1 ${pattern}*`
rc=$?
if [ $rc -ne 0 ]
then
echo "Today's file has yet not arrived";
exit 6;
else
if [ `echo $filename | wc -w` -ne 1 ]
then
echo "More than one file has arrived today. Check with Ops Analyst"
exit 6;
fi
cp /u03/PBIDW/data/backup/${filename} /u03/PBIDW/data/inbound
rc=$?
if [ $rc -ne 0 ]
then
echo "Copy of file $filename to /u03/PBIDW/data/inbound failed"
exit 6
else
echo "Copy of file $filename to /u03/PBIDW/data/inbound was successful"
fi
cd /u03/PBIDW/data/inbound;
new_filename=${filename%TXT*}"TXT"
echo $new_filename
mv $filename $new_filename
echo "new Filename = "$new_filename
fi
else
for filename in `cd /u03/UBIDW/data/inbound;ls -1 $filelist`
do
mv /u03/UBIDW/data/inbound/${filename} /u03/UBIDW/data/error/${filename}_`date '+%y%m%d%H%M%S'`
rc=$?
if [ $rc -ne 0 ]
then
echo "Move of file $filename to /u03/UBIDW/data/error failed"
exit 6
else
echo "Move of file $filename to /u03/UBIDW/data/error was successful"
fi
done
fi
exit 0
I have to make modifications in this script to run that task meantioned above...
Any suggestions what changes I have to made to this scripts?
Thanks a ton for your support :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2010 06:13 PM
10-25-2010 06:13 PM
Re: Script
#Set up the source and destination directories
srce=/u03/UBIDW/data/BART
dest=/u03/UBIDW/data/inbound
# Assuming you have located the source file:
# perhaps using the ls command.
cd $srce
pattern="${filelist}[_,.]$(date '+%y%m%d')"
filename=$(ls -1 ${pattern}*)
.
.
.
# first generate a new name - remove everything between ".TXT_" and ".gz" - ie. the date-time stamp
newfile=$(echo $filename | sed 's/\.TXT_.*\.gz//').TXT.gz
# Now move the file to the destination
mv $srce/$filename $dest/$newfile
# And, finally, uncompress it
gunzip $dest/$newfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2010 12:48 AM
10-26-2010 12:48 AM
Re: Script
That was such a quick response, I will try to make script in office today.
Thanks for making the meaning of the lines clear to me.
You have included everyting in script :)
Best Regards
Shikha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2010 02:20 PM
10-26-2010 02:20 PM
Re: Script
I have written the script in test enviorment and it looks like this:
I have attached it in a notepad..Can you please check if I have properly closed loops of IF by doing fi and can you see any other typo error in it?
Thanks Again :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2010 03:45 PM
10-26-2010 03:45 PM
Re: Script
Scripts shuld begin with a "she-bang" line that defines the interpreter to use. Add:
#!/usr/bin/sh
...to yours. Then, verify the syntax with:
# sh -n ./scriptname
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2010 03:54 PM
10-26-2010 03:54 PM
Re: Script
I apologize, I pasted it wrong , actually it loooks like the file which is attached now .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2010 03:58 PM
10-26-2010 03:58 PM
Re: Script
However I will go to office after 3 days now.
Apologies for delay.
This was my first script.
Thanks a ton for helping me with this. that too with quick response :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2011 10:14 PM
01-18-2011 10:14 PM