- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Shell scripting 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
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
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
02-15-2012 04:03 AM
02-15-2012 04:03 AM
Shell scripting help
Hi
I'm writing a shell script to carry out some user checks on more than one server.
I have a main script which is run from a central server ( so to speak ).
This main script calls another sub-script on the remote servers, using ssh -n <node> script.
The ssh process for remote script invocation sometimes hang and as a result the main script waits indefinitely for the ssh to finish. But when I check on the remote node, I cannot find the sub-script running.
I need a method to check for these hanging ssh processes in my main script and terminate them after a set timeout.
However I do not want the main script to wait for a timeout period after each invocation of ssh.
Main script invoking ssh -
awk // /etc/passwd | while read line
do
CUNAME="$(echo ${line} | awk -F: '{ print $1 }')"
CUID="$(echo ${line} | awk -F: '{ print $3 }')"
#echo ${CUNAME} | ${GREP} -f /admin/CK_UNIX/CK_UNIX_ignore_users.lis > /dev/null
${GREP} -w "${CUNAME}" /admin/CK_UNIX/CK_UNIX_ignore_users.lis > /dev/null
if [ $? -ne 0 ]
then
#echo ${CUNAME}
for Node in ${CAE_MGT} ${CAE_ALL}
do
SSH_CMD="ssh -n ${Node} ${CK_UNIX_DIR}/CK_UNIX_verify_user.ksh -u ${CUNAME} -i ${CUID}"
if [[ "${Node}" = "fils2005" || "${Node}" = "fils2006" ]]
then
SHELL2USE="/bin/sh"
SSH_CMD="ssh -n ${Node} ${SHELL2USE} ${CK_UNIX_DIR}/CK_UNIX_verify_user.ksh -u ${CUNAME} -i ${CUID}"
fi
RETVAL="$(${SSH_CMD})"
done
fi
done
The main script sometimes waits for the "ssh -n ${Node} ${CK_UNIX_DIR}/CK_UNIX_verify_user.ksh -u ${CUNAME} -i ${CUID}" to process to finish ( since this process does not finish, even after the sub-script CK_verify_user.ksh has existed on the remote node ).
Thank you all for your valuable comments.
Regards
K
- Tags:
- ssh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2012 12:28 AM
02-16-2012 12:28 AM
Re: Shell scripting help
I don't know what your CK_UNIX_verify_user.ksh script is doing, but it doesn't sound like something terribly complicated that should cause a hang?
>> The ssh process for remote script invocation sometimes hang and as a result the main script waits indefinitely for the ssh to finish. But when I check on the remote node, I cannot find the sub-script running.
Are you sure it ever actually got to run? Are you sure that ssh is setup correctly such that the remote system isn't requesting a password? Whenever I include ssh in a script is add the -o "batchmode yes" argument to my ssh command line so I know I'll get an error rather than a hang in that situation.
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2012 06:41 AM
02-16-2012 06:41 AM
Re: Shell scripting help
Hi
The sub-script prints some messages to the console, messages such as "Invalid user" , "User OK" and soon.
I found this info about ssh hang
http://www.openssh.org/faq.html#3.10, look at section 3.10.
Since this is what I'm seeing in my script and I cannot really redirect the output to dev/null, I modified the script slightly
for line in $(awk -F: '{ printf "%s:%s\n",$1,$3 }' /etc/passwd)
do
CUNAME="$(echo ${line} | awk -F: '{ print $1 }')"
CUID="$(echo ${line} | awk -F: '{ print $2 }')"
${GREP} -w "${CUNAME}" /admin/CK_UNIX/CK_UNIX_ignore_users.lis > /dev/null
if [ $? -ne 0 ]
then
#echo ${CUNAME}
for Node in ${MGT_NODES} ${ALL_NODES}
do
case ${Node} in
esuk1man|eguk1man)
SSH_CMD="ssh ${Node} ${CK_UNIX_DIR}/CK_UNIX_verify_user.ksh -u ${CUNAME} -i ${CUID}"
${SSH_CMD}
;;
eguk1ds[12])
# Nothing to do on these nodes
;;
*)
RPASSWDLINE="$(ssh ${Node} grep -w ${CUNAME} /etc/passwd)"
if [ "X${RPASSWDLINE}" != "X" ]
then
RUID="$(echo ${RPASSWDLINE} | awk -F: '{ print $3 }')"
if [ "X${CUID}" != "X${RUID}" ]
then
print_message ${Node} 1 ${CUNAME}
fi
fi
;;
esac
done
fi
done
However I cannot explain why ssh works without any problem for the two nodes esuk1man and eguk1man.
Thanks and Regards
K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2012 03:31 PM
02-16-2012 03:31 PM
Re: Shell scripting help
>${GREP} -w "${CUNAME}" /admin/CK_UNIX/CK_UNIX_ignore_users.lis > /dev/null
This isn't your problem but you can remove that /dev/null by using -q:
${GREP} -q -w "${CUNAME}" /admin/CK_UNIX/CK_UNIX_ignore_users.lis