hey there,
today I was unable to log into my private irc server. Really strange, since I changed nothing, the server was still running and all. Also my screen session seemed to have vanished.
After I asked another user I heard I was still in the channel... somehow my screen session was off the radar but still running, so I could not connect to it. Also since in this session I already was logged into the irc server, I could not log in again.
Well, killing the session and opening a new one was easy, but had I not asked my friend I could have been debugging for days without ever getting the idea I would still be logged in from somewhere.
So, every detail matters, even a "crashed" screen session :D
Showing posts with label bash. Show all posts
Showing posts with label bash. Show all posts
2012-06-28
2012-06-03
backup script (NO, not data-backups, small configuration file backups)
Hello again,
after some time finally something usefull for more of you: a small bash script that came out of configuration work. The scenario is, you want to test a new configuration file, but want to backup the old or standard one. Sometimes it's a hole directory you want to exchange. And ofter some testing one has a couple of backup files, all with different names and naming conventions, somtimes maybe a date, sometimes a tag...
So I wrote the following script. Probably most admins do something like this and probably there are already a quadrillion tools out there, that do this or can do this. But I like to have a simple command that does exactly what I want without the need to supply the same options everytime, that I can't remember. So if you have a tool already, just make an alias. But here's the script, for everyone who wants to use it:
#!/bin/bash
# put it here for example: /usr/local/bin/bak.sh
# don't forget to chmod 755 it
if [[ (($# -ne 1) && ($# -ne 2)) || ($1 == "-h") ]]; then
echo "usage: bak.sh <file or dir> <optional tag>"
echo "files will just be copied"
echo "directories will be archieved as .tgz"
exit
fi
APPEND="bak-`date +'%Y-%M-%d_%H%M%S'`"
if [ $# -eq 2 ]; then
APPEND="${APPEND}-${2}"
fi
if [ -d $1 ]; then
APPEND="${APPEND}.tgz"
echo "backing up ${1} to ${1}.${APPEND}"
tar czf $1.$APPEND $1
else
echo "backing up $1 to ${1}.${APPEND}"
cp -p $1 $1.$APPEND
fi
after some time finally something usefull for more of you: a small bash script that came out of configuration work. The scenario is, you want to test a new configuration file, but want to backup the old or standard one. Sometimes it's a hole directory you want to exchange. And ofter some testing one has a couple of backup files, all with different names and naming conventions, somtimes maybe a date, sometimes a tag...
So I wrote the following script. Probably most admins do something like this and probably there are already a quadrillion tools out there, that do this or can do this. But I like to have a simple command that does exactly what I want without the need to supply the same options everytime, that I can't remember. So if you have a tool already, just make an alias. But here's the script, for everyone who wants to use it:
#!/bin/bash
# put it here for example: /usr/local/bin/bak.sh
# don't forget to chmod 755 it
if [[ (($# -ne 1) && ($# -ne 2)) || ($1 == "-h") ]]; then
echo "usage: bak.sh <file or dir> <optional tag>"
echo "files will just be copied"
echo "directories will be archieved as .tgz"
exit
fi
APPEND="bak-`date +'%Y-%M-%d_%H%M%S'`"
if [ $# -eq 2 ]; then
APPEND="${APPEND}-${2}"
fi
if [ -d $1 ]; then
APPEND="${APPEND}.tgz"
echo "backing up ${1} to ${1}.${APPEND}"
tar czf $1.$APPEND $1
else
echo "backing up $1 to ${1}.${APPEND}"
cp -p $1 $1.$APPEND
fi
2012-05-28
ping tool / debugging a server from afar
hello readers,
sometimes my server is unreachable for no apparent reason. The logs don't really give a clue and my only way of reaching it again is to restart it by sending it an automatic hardware reset.
Since I have no idea whether it is locked up, just unreable *from* the network or completly disconnected from the network I wrote a little script to log pings. This way I can see in the log if it tries to ping at all and if it tries, if it can reach the network from its side or not.
Now all I have to do is to wait for it to crash. Well, I mean, to hope for the script to be a useless effort since it will never crash again ... of course ... ;)
Here's the script:
#!/bin/bash
# filename: pinglog.sh
# set logging dir here
MYDIR=/var/log/ping
# here you can choose a different format, i.e. "$1.log"
# where $1 always is the hostname given to the script
MYFILENAME="$1"
echo `date +'%Y-%m-%d %H:%M: '` `ping -c1 $1 | head -n2 | tail -n1` >>\ $MYDIR/$MYFILENAME
and here's a line for you to enter in in the crontab, if you want it to ping&log every 5minutes:
*/5 * * * * /some/directory/pinglog.sh some.server.com
I know it's not something big or difficult, but sometimes big problems need low-tech solutions. Also small scripts like these can be a good alternative to installing big software packages like nagios, if you don't really need them.
sometimes my server is unreachable for no apparent reason. The logs don't really give a clue and my only way of reaching it again is to restart it by sending it an automatic hardware reset.
Since I have no idea whether it is locked up, just unreable *from* the network or completly disconnected from the network I wrote a little script to log pings. This way I can see in the log if it tries to ping at all and if it tries, if it can reach the network from its side or not.
Now all I have to do is to wait for it to crash. Well, I mean, to hope for the script to be a useless effort since it will never crash again ... of course ... ;)
Here's the script:
#!/bin/bash
# filename: pinglog.sh
# set logging dir here
MYDIR=/var/log/ping
# here you can choose a different format, i.e. "$1.log"
# where $1 always is the hostname given to the script
MYFILENAME="$1"
echo `date +'%Y-%m-%d %H:%M: '` `ping -c1 $1 | head -n2 | tail -n1` >>\ $MYDIR/$MYFILENAME
and here's a line for you to enter in in the crontab, if you want it to ping&log every 5minutes:
*/5 * * * * /some/directory/pinglog.sh some.server.com
I know it's not something big or difficult, but sometimes big problems need low-tech solutions. Also small scripts like these can be a good alternative to installing big software packages like nagios, if you don't really need them.
Subscribe to:
Posts (Atom)