- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- For loop -> reading variables from a text file.
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
06-27-2003 10:10 AM
06-27-2003 10:10 AM
>opcnode -add_node node_name=VARIABLE1 net_type=NETWORK_IP mach_type=MACH_OTHER group _name=VARIABLE2 node_label=VARIABLE3
In other words I want to feed the above command from a text file file which will contain VARIABLE1 VARIABLE2 VARIABLE3
I know how to do this in NT but not in UNIX.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2003 10:16 AM
06-27-2003 10:16 AM
Re: For loop -> reading variables from a text file.
cat yourFile |
while read v1 v2 v3
do
opcnode -add_node node_name=v1 net_type=NETWORK_IP mach_type=MACH_OTHER group _name=v2 node_label=v3
if [[ "$?" != "0" ]] ;then
your message
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2003 10:18 AM
06-27-2003 10:18 AM
Re: For loop -> reading variables from a text file.
opcnode -add_node node_name=v1 net_type=NETWORK_IP mach_type=MACH_OTHER group _name=v2 node_label=v3
should be
opcnode -add_node node_name=$v1 net_type=NETWORK_IP mach_type=MACH_OTHER group _name=$v2 node_label=$v3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2003 10:19 AM
06-27-2003 10:19 AM
Re: For loop -> reading variables from a text file.
while read VARIABLE1 VARIABLE2 VARIABLE3
do
opcnode -add_node node_name=$VARIABLE1 net_type=NETWORK_IP mach_type=MACH_OTHER group _name=$VARIABLE2 node_label=$VARIABLE3
done < file
Where file is your text file.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2003 10:30 AM
06-27-2003 10:30 AM
Re: For loop -> reading variables from a text file.
#!/usr/bin/sh
exec 0while read -r VAR1 VAR2 VAR3
do
opcnode -add_node node_name=$VAR1 net_type=NETWORK_IP mach_type=MACH_OTHER group _name=$VAR2 node_label=$VAR3
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2003 10:32 AM
06-27-2003 10:32 AM
Re: For loop -> reading variables from a text file.
if [[ "$?" != "0" ]] ;then
your message
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2003 10:38 AM
06-27-2003 10:38 AM
Re: For loop -> reading variables from a text file.
$ date
$ echo $?
0
$ ls myfile
myfile not found
$ echo $?
2
So the body of the if statement will be executed if the previous executed command fails.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2003 04:11 AM
06-30-2003 04:11 AM
Re: For loop -> reading variables from a text file.
var1=`cat txtfiles | cut -c1-5`
var2=`cat txtfiles | cut -c6-10`
where c1 is the 1st char of line thru last char
& c6 is the the 1st char of 2nd field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2003 06:41 AM
06-30-2003 06:41 AM
Solutionstart with a while loop that reads the contents of a flat file into variables.
while read var1 var2 var3
do
opcnode -add_node node_name=${var1}net_type=
if [[ $? -eq 0 ]]
then
# your job passed ok without any errors
echo "passed ${var1}"
else
echo "failed ${var1}"
fi
done < file
the $?
contain the exit code for the last command.
in unix, 0 (zero) always indicate a success, unless otherwise noted.
see the man page for the command, it always has the exit code towards the bottom.
live free or die
donny