- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell programing
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
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
тАО03-27-2006 09:39 PM
тАО03-27-2006 09:39 PM
for example
more 123.txt
aa
bb
cc
dd
I need to make script that could read these strings from 123.txt and write them in another txt file.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2006 09:40 PM
тАО03-27-2006 09:40 PM
Re: Shell programing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2006 09:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2006 09:49 PM
тАО03-27-2006 09:49 PM
Re: Shell programing
if you insists on a script:
#!/usr/bin/sh
while read record
do
echo $record >> output.txt
done < 123.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2006 09:53 PM
тАО03-27-2006 09:53 PM
Re: Shell programing
More ways to simply copy the file contents to new.
cat file > newfile
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2006 09:53 PM
тАО03-27-2006 09:53 PM
Re: Shell programing
for i in 1 2 3
do
command ${variable}
done
I need to get aa then bb and cc from 123.txt and put it into my script instead of variable.
How to do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2006 10:00 PM
тАО03-27-2006 10:00 PM
Re: Shell programing
for i in 1 2 3
do
while read variable;
do
command ${variable}
done < 123.txt
done
That is it.
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2006 10:03 PM
тАО03-27-2006 10:03 PM
Re: Shell programing
Post requirement as:
1) input
2) expected output from input
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2006 10:20 PM
тАО03-27-2006 10:20 PM
Re: Shell programing
1. I have txt file containing list of remote hosts.
host1
host2
host3 etc
2. I need to do script that reads host1 from txt file and ssh to host1 do the command then exit from host1, and this action must be done for all hosts ( host2, host3.. etc).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2006 10:25 PM
тАО03-27-2006 10:25 PM
Re: Shell programing
host1
host2
host3 etc
2. I need to do script that reads host1 from txt file and ssh to host1 do the command then exit from host1, and this action must be done for all hosts ( host2, host3.. etc).
>>>>>>>>
Simply as,
put all hosts in > hosts file. So host1,host2 and etc are in hosts file.
while read host;
do
ssh
done < hosts
If you don't want to specify the hostname then,
while read host;
do
ssh ${host} 'command'
done < hosts
will do that.
PS: Hope you have set key transaction between hosts for not asking password. Else it will ask password.
--
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-27-2006 10:30 PM
тАО03-27-2006 10:30 PM
Re: Shell programing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2006 01:52 AM
тАО03-28-2006 01:52 AM
Re: Shell programing
root@lev /Ignite_Bckp>more test.sh
while read host;
do
ssh ${host}
done < hosts_test.txt
and file containing hosts (in the same dir)
root@lev /Ignite_Bckp>more hosts_test.txt
adam
kate
when executing script test.sh I get error:
root@lev /Ignite_Bckp>chmod +x hosts_test.txt
root@lev /Ignite_Bckp>./hosts_test.txt
./hosts_test.txt: adam: not found.
./hosts_test.txt[2]: kate: not found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2006 02:13 AM
тАО03-28-2006 02:13 AM
Re: Shell programing
You reversed the files and are trying to exectue the data (.txt) file.
Try:
chmod +x test.sh
./test.sh
Also... I generally preferr to keep the parameter out of the script file. You your case that means removing the "< node_test.txt" fromt eh .sh
The activate the shell script providing whatever data is appropirate at the moment, possibly even entering lines manually:
./test.sh < node_test.txt
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2006 02:35 AM
тАО03-28-2006 02:35 AM
Re: Shell programing
a simple 'ssh' will leave stdin open, so a successful connection will read all but the first value of the loop.
Use:
while read host
do ssh -n $host
done
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2006 02:40 AM
тАО03-28-2006 02:40 AM
Re: Shell programing
Try to enable the public key mechanism.
Look at this procedure and check for the following lines in sshd.conf file :
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile ~/.ssh/authorized_keys
These lines should be uncommented.
After this you'll be able to do : sftp/scp/ssh between this hosts without password asking.
Another possibility for shell scripting ;
#!/sbin/sh
for SERVER in `cat hosts.txt`
do
ssh $SERVER <
command 2
command n
EOF
done
Hope this help
Kenavo
Pat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2006 05:37 AM
тАО03-28-2006 05:37 AM
Re: Shell programing
# use file /tmp/host.list
# file name is : xxxxx
for i in $(cat /tmp/host.list)
do
echo "do something on : $i"
ssh root@$i "command;command"
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2006 01:13 PM
тАО03-28-2006 01:13 PM
Re: Shell programing
Thanks to all for advices. My scrips works fine now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2006 02:14 PM
тАО03-28-2006 02:14 PM
Re: Shell programing
You can close this thread now.
-Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2006 02:17 PM
тАО03-28-2006 02:17 PM