- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Scripting clarification
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
Discussions
Discussions
Forums
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
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
тАО04-02-2009 07:02 PM
тАО04-02-2009 07:02 PM
Scripting clarification
I just want to know how to read a file through script. My requirement is i want to take backup if a file contain the fifth line as "yes". If "Yes" word is there means i need to fire a backup. "No" means i should not.
I am already having a script for only taking the backup. I want to execute through command.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2009 07:27 PM
тАО04-02-2009 07:27 PM
Re: Scripting clarification
there are several ways to read the file in to a script.
eg:
cat file | while read LINE
do
:
:
done
you can either count to the 5th line, or look for a string BACKUP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2009 07:59 PM
тАО04-02-2009 07:59 PM
Re: Scripting clarification
The fifth line is only "Yes" or "No". Can you provide any sample script for the same.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2009 08:25 PM
тАО04-02-2009 08:25 PM
Re: Scripting clarification
FILE=/path/filename
count=1
cat $FILE | while read LINE
do
if [[ LNUM -eq 5 && LINE = "Yes" ]]
then
do_backup
commands here
fi
(( count += 1 )) <- check syntax
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2009 08:26 PM
тАО04-02-2009 08:26 PM
Re: Scripting clarification
change this line:
if [[ $count -eq 5 && $LINE = "Yes" ]]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2009 09:06 PM
тАО04-02-2009 09:06 PM
Re: Scripting clarification
here one more script
[root@rspc521 tmp]# cat srvlist
server1
server2
server3
server4
Yes
server6
server7
[root@rspc521 tmp]# cat myscript
ans=`sed -n '5,5p' srvlist`
if [ $ans=="yes" ]
then
echo " your backup script"
fi
Suraj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2009 11:16 PM
тАО04-02-2009 11:16 PM
Re: Scripting clarification
I can understand well about your script.
But i am getting following error,
# ./script2
./script2[3]: [sed: not found.
below mentioned script for your convenience.
# pg script1
#!/usr/bin/sh
server1
server2
server3
server4
Yes
server5
server6
--------------------------------------------
# pg script2
#!/usr/bin/sh
ans='sed -n'5,5p'script1'
if [$ans=="Yes"]
then
echo "Your current Location"
pwd
date
fi
--------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-02-2009 11:24 PM
тАО04-02-2009 11:24 PM
Re: Scripting clarification
Script is good,
but in your environment it can find the
sed editor, or you do not have one
(but that last would be strange)
usual the path is
[root@orasrv1:]/root<>>> which sed
/usr/bin/sed
[root@orasrv1:]/root<>>>
do
export PATH=/usr/bin:$PATH
in your script or session
before running sed command
have fun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2009 12:15 AM
тАО04-03-2009 12:15 AM
Re: Scripting clarification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2009 12:19 AM
тАО04-03-2009 12:19 AM
Re: Scripting clarification
I am very new to scripting language. I have tried like you said but its still not working i have entered like below required your suggestion..
#!/usr/bin/sh
ans='sed -n'5,5p'script1'
if [$ans=="Yes"]
then
echo "Your current Location"
pwd
date
fi
export PATH=/usr/bin:$PATH
--------------------------------------------
I need to execute this urgent manner...