- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- doubt in script
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-31-2012 10:40 PM
10-31-2012 10:40 PM
doubt in script
Hi Team,
I am quite new to the field of scripting .
In one of our server we have one script which is using for removing the tapes from the library. I am attaching one of the script below , is it possible for you to tell me what will happen while this script is get executed.
#!/usr/bin/sh
#Input : scan thru all tape eject log files
#Output : list of dates files with tapes returning on that day.
#Usage : tapereturn.sh _today_YYYYMMDD_
>/tmp/tapereturn.txt
LOGDIR="/u11/library/log/"
if [[ $# -eq 0 ]] then
echo "Usage tapereturn.sh _today_YYYYMMDD_"
echo "No argument pass exit script"
exit
fi
FILESET="*eject*$1*"
for a in `ls $LOGDIR$FILESET`
do
# echo "$a"
grep "expiration" $a |awk '{print $1 " " $NF}' >>/tmp/tapereturn.txt
done
while read tape return_date
do
rd_file="return_on_`echo $return_date |tr \/ \_ `" # Determine what is the return date file name
touch /u11/library/log/returntape/$rd_file
# Added these to ensure the return file always belongs to library id to avoid error
chown library:osgadm /u11/library/log/returntape/$rd_file
chmod 640 /u11/library/log/returntape/$rd_file
#
grep -q $tape /u11/library/log/returntape/$rd_file # check if this tape already mention in return file
if [[ $? -ne 0 ]] then # Cannot find tape in rd_file, means new instances
echo "$tape backup on $1" >> /u11/library/log/returntape/$rd_file
fi
# Else tape already found in rd_file due to rerun.
done </tmp/tapereturn.txt
rm /tmp/tapereturn.txt
Mainly i have one doubt on what this >/tmp/tapereturn.txt will do and what is the action of while statement here .
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2012 12:32 AM - edited 11-01-2012 12:33 AM
11-01-2012 12:32 AM - edited 11-01-2012 12:33 AM
Re: question on script
>I have one question on what this >/tmp/tapereturn.txt will do
This either creates an empty file or resets the EOF to 0.
>what is the action of while statement here .
At a high level the while loop finds tapes that are in the log directory with *expire* in their names.
Then it adds these tapes to the returntape/return_on_* file.
while read tape return_date; do
...
done </tmp/tapereturn.txt
Reads each record in tapereturn.txt and assigns the first field to tape and the rest to return_date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2012 12:38 AM
11-01-2012 12:38 AM
Re: doubt in script
>/tmp/tapereturn.txt
This just truncates the file /tmp/tapereturn.txt to length 0 (i.e. if the file still exists, its contents are deleted, if it doesn't exist, it is created empty) Effectively this is redirecting "nothing" to the file.
while read tape return_date do rd_file="return_on_`echo $return_date |tr \/ \_ `" # Determine what is the return date file name touch /u11/library/log/returntape/$rd_file # Added these to ensure the return file always belongs to library id to avoid error chown library:osgadm /u11/library/log/returntape/$rd_file chmod 640 /u11/library/log/returntape/$rd_file # grep -q $tape /u11/library/log/returntape/$rd_file # check if this tape already mention in return file if [[ $? -ne 0 ]] then # Cannot find tape in rd_file, means new instances echo "$tape backup on $1" >> /u11/library/log/returntape/$rd_file fi # Else tape already found in rd_file due to rerun. done </tmp/tapereturn.txt
This reads each line out of /tmp/tapereturn.txt, which is presumably made up of 2 columns listing a tape and a return date. This information is used to create or update a file in /u11/library/log/returntape which is called return_on_<date> (although there's no indication in the script of what the <date> field will look like, except to say the fields in the date will be delimited by underscores "_" . What goes into this file? Well basically if it doesn't already contain a mention of the tape, then a line is appended mentioning the tape and return date.
Of course, most backup software these days has full media management functionality meaning you shouldn't have to "roll your own" scripts like this. I'm guessing at this site you have no proper backup software and are using tar/cpio/vxdump/fbackup or something like that?
I am an HPE Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2012 01:21 AM
11-01-2012 01:21 AM
Re: doubt in script
Hi Duncan,
Thanks for the reply.
In the script there is one variable having the below value
FILESET="*eject*$1*"
What this $1 implies .
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2012 01:54 AM
11-01-2012 01:54 AM
Re: question on script
>What this $1 implies?
$? is the current first argument to the script/function, your date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2012 10:25 PM
11-01-2012 10:25 PM
Re: question on script
Hi DH,
Thanks for the update.
In that script i want to see the output of tapereturn.txt, hence i added one more line for copying the tapereturn.txt to another directory, But this copying is not hapenning. Please see the below updated script, my aim is to copy the file tapereturn.txt to my home directory. Could you please have a look on this and let me know whether i made any mistake
#!/usr/bin/sh
#Input : scan thru all tape eject log files
#Output : list of dates files with tapes returning on that day.
#Usage : tapereturn.sh _today_YYYYMMDD_
>/tmp/tapereturn.txt
LOGDIR="/u11/library/log/"
if [[ $# -eq 0 ]] then
echo "Usage tapereturn.sh _today_YYYYMMDD_"
echo "No argument pass exit script"
exit
fi
FILESET="*eject*$1*"
for a in `ls $LOGDIR$FILESET`
do
# echo "$a"
grep "expiration" $a |awk '{print $1 " " $NF}' >>/tmp/tapereturn.txt
done
/usr/bin/cp -p -r /tmp/tapereturn.txt /u01/osg/adm/babula/ ####This one i added for copying the file to my home directory
while read tape return_date
do
rd_file="return_on_`echo $return_date |tr \/ \_ `" # Determine what is the return date file name
touch /u11/library/log/returntape/$rd_file
# Added these to ensure the return file always belongs to library id to avoid error
chown library:osgadm /u11/library/log/returntape/$rd_file
chmod 640 /u11/library/log/returntape/$rd_file
#
grep -q $tape /u11/library/log/returntape/$rd_file # check if this tape already mention in return file
if [[ $? -ne 0 ]] then # Cannot find tape in rd_file, means new instances
echo "$tape backup on $1" >> /u11/library/log/returntape/$rd_file
fi
# Else tape already found in rd_file due to rerun.
done </tmp/tapereturn.txt
rm /tmp/tapereturn.txt
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2012 11:57 PM
11-01-2012 11:57 PM
Re: question on script
>But this copying is not happening.
It seems like it should but it happening multiple times.
Move it to the bottom:
done </tmp/tapereturn.txt
cp -p /tmp/tapereturn.txt /u01/osg/adm/babula/ ####This one I added
rm /tmp/tapereturn.txt
Do you have permission to write to your home directory? (Are you yourself, when you run the script?)
(Also no need for recursion, -r).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2012 12:07 AM
11-02-2012 12:07 AM
Re: question on script
Hi Dennis,
What you told may be right .. May be permission is making the issue .. Now i created a directory having full access in /tmp and copied the tapereturn.txt file to there.
Lets see is it working ?
Regards