суббота, 1 января 2011 г.

Nice tip

After accidentally rebooting the wrong server a couple times, forgetting what I had ssh’ed to, I decided on a handy fix, this /usr/local/bin/confirm script:
#!/bin/sh
echo "You are about to run the command '$*' on `hostname`." >&2
echo -n "Are you sure this is what you want to do? (Y/N): [N] " >&2
read x || exit
case "$x" in
[Yy]*)  exec "$@" ;;
*)      echo "Command '$*' aborted." >&2  ; exit 1 ;;
esac
Now, on my servers I add these aliases to root’s .bashrc file:
alias halt=’confirm halt’; alias reboot=’confirm reboot’
That’s saved me a few times since then. The .bashrc file also already had the “alias rm=’rm -i’” in there, which at first I hated, but learned to like it after it too saved my skin on more than one occasion.
@via http://www.cyberciti.biz/tips/my-10-unix-command-line-mistakes.html

Комментариев нет: