|
Saturday, 03 April 2010 12:40 |
// dot this script, don't just run it as a script (which would run it in its own sub-shell) because you need the variables to be set in the context of your current shell.
#!/bin/bash
for FILE in $(find /tmp/ssh-???*[0-9]* -type s -user ${LOGNAME} -name "agent.[0-9]*")
do
GOT_AGENT=0
SOCK_PID=${FILE##*.}
PID=$(ps -fu${LOGNAME}|awk '/ssh-agent/ && ( $2=='${SOCK_PID}' || $3=='${SOCK_PID}' || $2=='${SOCK_PID}' +1 ) {print $2}')
SOCK_FILE=${FILE}
SSH_AUTH_SOCK=${SOCK_FILE}; export SSH_AUTH_SOCK;
SSH_AGENT_PID=${PID}; export SSH_AGENT_PID;
ssh-add -l | grep : > /dev/null
if [ $? = 0 ]
then
GOT_AGENT=1
echo "Agent pid ${PID}"
break
fi
echo "Skipping pid ${PID}"
done
if [ $GOT_AGENT = 0 ]
then
ssh-add
fi
Before I used the find I was using this, but it's not as accurate, and the socket file is more important than the PID when you're trying to connect to an existing agent, so it makes sense to me to start with that.
(unless your find would be horribly slow for some reason)
for PID in $(ps -furoot | awk '/ssh-agent/{print $2}')
do
let SOCK_PID=PID-1
SOCK_FILE=$(ls -d /tmp/ssh-???*${SOCK_PID}/agent.${SOCK_PID})
 Read more: |
|
Sunday, 07 March 2010 21:18 |
Loopia dynamic dns updater
#!/bin/bash
# Config
Username="username"
Password="password"
Hostname="sub.domain.com"
daemon=3600 # check every 3600 seconds (one hour)
syslog=yes # log update msgs to syslog
pidfile=/var/run/loopiaddclient.pid # record PID in file.
# Do not edit bellow this line
if [ -f "${pidfile}" ]; then
# The file exists so read the PID
# to see if it is still running
MYPID=`head -n 1 $pidfile`
if [ -n "`ps -p ${MYPID} | grep ${MYPID}`" ]; then
echo `basename $0` is already running [$MYPID].
exit
fi
fi
# Echo current PID into lock file
echo $$ > $pidfile
echo "Launching Loopia DNS Updater"
IPaddr="0"
while a=a
do
IPaddrNy=`curl -s dns.loopia.se/checkip/checkip.php | sed 's/^.*: \([^<]*\).*$/\1/'`
if [ $IPaddr != $IPaddrNy ]
then
IPStatus="$(curl -s --user "$Username:$Password" "https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname=$Hostname&myip="`curl -s dns.loopia.se/checkip/checkip.php | sed 's/^.*: \([^<]*\).*$/\1/'`)"
if [ $syslog = "yes" ]
then
case "$IPStatus" in
"good" )
echo "IP adress for $Hostname is updated to $IPaddrNy"
;;
"nochg" )
echo "No change needed for $Hostname, will check again in $daemon seconds."
;;
* )
echo "Unknown server response: $syslog"
;;
esac
fi
IPaddr=$IPaddrNy
fi
sleep $daemon
done
viagra generique pas cher viagra sans ordonnance viagra europe sildenafil acheter acheter viagra 100mg viagra meilleur prix viagra pour femme viagra acheter en france acheter viagra livraison rapide viagra vente en ligne viagra achat en ligne acheter viagra en france acheter viagra sur le net achat viagra en france achat viagra generique procurer viagra commander viagra en ligne cialis sur le net cialis prix cialis acheter en france cialis generique en ligne cialis achat generique commander cialis en ligne acheter cialis en france cialis acheter en ligne levitra europe levitra prix levitra acheter en france levitra generique en ligne levitra achat generique commander levitra en ligne acheter levitra en ligne acheter levitra sur le net kamagra prix commander kamagra en ligne kamagra vente acheter kamagra en gel kamagra pas cher kamagra site fiable kamagra sachet kamagra a vendre
#!/bin/bash
# Config
Username="username"
Password="password"
Hostname="sub.domain.com"
daemon=3600 # check every 3600 seconds (one hour)
syslog=yes # log update msgs to syslog
pidfile=/var/run/loopiaddclient.pid # record PID in file.
# Do not edit bellow this line
if [ -f "${pidfile}" ]; then
# The file exists so read the PID
# to see if it is still running
MYPID=`head -n 1 $pidfile`
if [ -n "`ps -p ${MYPID} | grep ${MYPID}`" ]; then
echo `basename $0` is already running [$MYPID].
exit
fi
fi
# Echo current PID into lock file
echo $$ > $pidfile
echo "Launching Loopia DNS Updater"
IPaddr="0"
while a=a
do
IPaddrNy=`curl -s dns.loopia.se/checkip/checkip.php | sed 's/^.*: \([^<]*\).*$/\1/'`
if [ $IPaddr != $IPaddrNy ]
then
IPStatus="$(curl -s --user "$Username:$Password" "https://dns.loopia.se/XDynDNSServer/XDynDNS.php?hostname=$Hostname&myip="`curl -s dns.loopia.se/checkip/checkip.php | sed 's/^.*: \([^<]*\).*$/\1/'`)"
if [ $syslog = "yes" ]
then
case "$IPStatus" in
"good" )
echo "IP adress for $Hostname is updated to $IPaddrNy"
;;
"nochg" )
echo "No change needed for $Hostname, will check again in $daemon seconds."
;;
* )
echo "Unknown server response: $syslog"
;;
esac
fi
IPaddr=$IPaddrNy
fi
sleep $daemon
done
 Read more: |