- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: script help?
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
тАО01-11-2007 09:48 AM
тАО01-11-2007 09:48 AM
An enduser is going to run a script. This script will ask questions and store the results. One of the questions is "What hosts are to have a copy of this log file?" Based on the answer, have this log file remote copied (using scp, of course!). The answer to the hosts question could be any number of hostnames from 1 to 40.
So my question is, in the script how would I account for a read that will have a varied number of responses?
Once I have these responses I need to loop through and scp the log file.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 09:59 AM
тАО01-11-2007 09:59 AM
SolutionYou can always use a temporary file to collect the n-read results. Then, re-read the temporary file to process:
#!/usr/bin/sh
typeset NAMES=/tmp/mynames
while read LINE
do
echo ${LINE} >> ${NAMES}
done
while read LINE
do
echo "processing ${LINE}..."
done < ${NAMES}
exit
Regards!
...JRF...
- Tags:
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 11:24 AM
тАО01-11-2007 11:24 AM
Re: script help?
What I am doing is making a useradd script for a shop of some 40 servers. Unfortunately NIS or LDAP is not is use and will not be (otherwise this would be easy)
On a server, the helpdesk will input the requisite values for the useradd. These values are stored in a log file.
Part of the script is to ask the helpdesk user what additional systems this user to be added to. Here the helpdesk user will type in the individual hostnames, each hostname followed by "ENTER", until the "X|x" character is pressed. At this time a log file of the entered hosts exists and is scp to the hosts that were entered in. Note, the number of servers will vary - could be 1 server or could be all 40 servers or could be any number of servers from 1-40.
- Tags:
- useradd
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 12:17 PM
тАО01-11-2007 12:17 PM
Re: script help?
#!/usr/bin/sh
export PATH=/usr/bin
set -A HOSTNAMES
echo "Enter hostnames, one per line and nothing for the last name:"
COUNT=0
REPLY=start
while [ "$REPLY" != "" ]
do
read REPLY
if [ "$REPLY" != "" ]
then
let COUNT=COUNT+1
HOSTNAMES[$COUNT]="$REPLY"
fi
done
if [ $COUNT -eq 0 ]
then
echo "No hostnames entered - exiting"
fi
echo "There are $COUNT hosts"
for HOST in ${HOSTNAMES[@]}
do
echo scp to host: $HOST
done
The scp line can be changed to the actual scp command. For truly robust scripting for a helpdesk, I would look for duplicates in the list and also validate that each host is valid (like a nsquery or nslookup to find the host). And while you're at it, add a check for successful scp completion.
Bill Hassell, sysadmin
- Tags:
- ARRAY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 12:21 PM
тАО01-11-2007 12:21 PM
Re: script help?
Here is how I handled it:
echo "Enter the system destination separated by spaces"
echo "(hqubl01, hquwh01, hquwh05, hquwh50, hquwh55, or all): "
read S36DEST
for SYS in ${S36DEST}
do
scp afile ${SYS}:adir
done
- Tags:
- for loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 01:00 PM
тАО01-11-2007 01:00 PM
Re: script help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-11-2007 02:11 PM
тАО01-11-2007 02:11 PM
Re: script help?
1) and array of known nodes in the script.
or
2) a quick lookup in a central file (/etc/hosts)
or
3) a ping
hth,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-12-2007 03:10 AM
тАО01-12-2007 03:10 AM