HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- wait output in a script
Operating System - Linux
1828926
Members
2905
Online
109986
Solutions
Forums
Categories
Company
Local Language
back
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
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
05-07-2008 08:24 AM
05-07-2008 08:24 AM
Hi all,
I am developing a script that does various functions and one of these is to check a user ssh connection from an AUTH server to the server where the script is running.
I want to make sure the user doesnt skip this step so I have written a bit of code:
read ANS?"Please copy and paste the authorised key for the CA user on $AUTHSERV here >>>"
if [[ $ANS = $KEY ]] ; then
print "ssh-rsa $ANS ca@AUTHSERV" > $CAHOME/.ssh/authorized_keys
chmod 644 $CAHOME/.ssh/authorized_keys
print "INFO: Key has been accepted, please test ssh connection from $AUTHSERV and ca account and run the command 'touch /
tmp/ldap_ssh_test' - - you have 5 minutes "
CheckSsh
else
print "The key you have entered does not match the key in $CONF/ldap.CFG, check ca user key on $AUTHSERV "
exit 204
fi
so when the key has been inputted correctly I want my script to run the CheckSsh funciton and wait for the user to run the touch command:
CheckSsh {
while [[ count -lt 60 ]]
do
if [[ -f /tmp/ldap_ssh_test ]] ; then
break
else
print ".\c"
sleep 5
fi
done
}
so the print ".\c" will print ...... every five seconds to show this is waiting.
I could also put in a sum to work out how much time the user has left.
my question is does anyone have any better syntax or ideas to display that the script is waiting?
thanks
chris.
I am developing a script that does various functions and one of these is to check a user ssh connection from an AUTH server to the server where the script is running.
I want to make sure the user doesnt skip this step so I have written a bit of code:
read ANS?"Please copy and paste the authorised key for the CA user on $AUTHSERV here >>>"
if [[ $ANS = $KEY ]] ; then
print "ssh-rsa $ANS ca@AUTHSERV" > $CAHOME/.ssh/authorized_keys
chmod 644 $CAHOME/.ssh/authorized_keys
print "INFO: Key has been accepted, please test ssh connection from $AUTHSERV and ca account and run the command 'touch /
tmp/ldap_ssh_test' - - you have 5 minutes "
CheckSsh
else
print "The key you have entered does not match the key in $CONF/ldap.CFG, check ca user key on $AUTHSERV "
exit 204
fi
so when the key has been inputted correctly I want my script to run the CheckSsh funciton and wait for the user to run the touch command:
CheckSsh {
while [[ count -lt 60 ]]
do
if [[ -f /tmp/ldap_ssh_test ]] ; then
break
else
print ".\c"
sleep 5
fi
done
}
so the print ".\c" will print ...... every five seconds to show this is waiting.
I could also put in a sum to work out how much time the user has left.
my question is does anyone have any better syntax or ideas to display that the script is waiting?
thanks
chris.
hello
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2008 09:11 AM
05-07-2008 09:11 AM
Solution
Hi Chris:
Your technique is fine. A nice polish to your own suggestion is to have your script spawn your CheckSsh() function as a background process.
Then, capture the PID of that process:
# PID=$!
Now, let the main part of your script do other work if/as necessary. If at any time you want to cancel the CheckSSh() wait, simply issue do:
# kill ${PID} in the script that called the function in the first place.
Regards!
...JRF...
Your technique is fine. A nice polish to your own suggestion is to have your script spawn your CheckSsh() function as a background process.
Then, capture the PID of that process:
# PID=$!
Now, let the main part of your script do other work if/as necessary. If at any time you want to cancel the CheckSSh() wait, simply issue do:
# kill ${PID} in the script that called the function in the first place.
Regards!
...JRF...
- Tags:
- background
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2008 11:53 AM
05-07-2008 11:53 AM
Re: wait output in a script
Hi (again) Chris:
Here's a prototype demonstration.
# cat ./mywaiter
#!/usr/bin/sh
typeset PID
function spout
{
while true
do
echo ".\c"
kill -s 0 ${PID} > /dev/null 2>&1
[ $? != 0 ] && return 0 || sleep 1
done
}
function grind
{
typeset -i N=0
while (( N < 30 ))
do
(( N=${N}+1 ))
echo "pass_${N}" >> /tmp/sh.$$
sleep 1
done
}
grind &
PID=$!
echo "pid=$$/${PID} executing -- please wait\c"
spout
echo "ok"
exit 0
# ./mywaiter
pid=10614/10615 executing -- please wait..............................ok
#
# head -3 /tmp/sh.10614
pass_1
pass_2
pass_3
Regards!
...JRF...
Here's a prototype demonstration.
# cat ./mywaiter
#!/usr/bin/sh
typeset PID
function spout
{
while true
do
echo ".\c"
kill -s 0 ${PID} > /dev/null 2>&1
[ $? != 0 ] && return 0 || sleep 1
done
}
function grind
{
typeset -i N=0
while (( N < 30 ))
do
(( N=${N}+1 ))
echo "pass_${N}" >> /tmp/sh.$$
sleep 1
done
}
grind &
PID=$!
echo "pid=$$/${PID} executing -- please wait\c"
spout
echo "ok"
exit 0
# ./mywaiter
pid=10614/10615 executing -- please wait..............................ok
#
# head -3 /tmp/sh.10614
pass_1
pass_2
pass_3
Regards!
...JRF...
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP