crontab

I’m setting up some backup scripts and am using cron to schedule them to run. Usually I run my backup scripts as root and just link a file into /etc/cron.*/ for periodic processing. However in this case I need to run the backup scripts as my user (they’re offsite backup scripts that use rsync to copy data) and not root, so I used crontab -e to edit my crontab. I did a little reading on crontab and learned about the @weekly syntax which I’ve used for the first time today. Now I guess I just wait a week and see that everything is working. :)

WinSCP command line options

Finally got around to taking a look at WinSCP’s command-line options. Basically I just needed to specify a session name and that was it. Now I have a set of icons on my desktop for scping to my various servers. I even configured a shortcut key for servers I use often, so now all I need to do to get at my remote ProgClub files is press Ctrl+Alt+Shift+C.

Bash aliases for listing hidden files

I finally figured out the ls command to list hidden files, and decided to setup a ~/.bash_aliases file for the first time. My ~/.bash_aliases file is now:

alias l.='ls -d .[!.]*'
alias ll.='ll -d .[!.]*'

So I have an “l.” command which will list hidden files and directories, and an “ll.” command which will list the same information in detail.

Keeping Your SSH Sessions Alive Through NAT Firewalls

I found this article Keeping Your SSH Sessions Alive Through Pesky NAT Firewalls which explained how to keep SSH connections alive through NAT firewalls. I’m behind a NAT router and my SSH connections are always timing out due to inactivity, and it annoys the shit out of me. I’ve been putting up with it for ages, and tonight I finally got around to searching for a solution. The solution is to edit your ~/.ssh/config file and add:

Host *
    ServerAliveInterval 240

That will make the server send a keep-alive packet every four minutes, which out to do it. Haven’t tried it yet, but expect it will work. Will configure my systems now…

Update: that didn’t seem to work for me. :(

Maybe this is a client setting?

Anyway, I did some more research, and I found that PuTTY has a configuration option in the Connection settings “Sending of null packets to keep session active”, “Seconds between keepalives” which defaults to 0 (turned off). So I’m gonna try with that now.

Setting a default value if a bash variable is undefined

Say you want to take an optional command line argument to your script. That means that maybe $1 is set to a value, or maybe it’s not. You can read out the value and assign a default in the case that $1 is not set using the syntax:

  variable=${1:-default-value}

Which will set $variable to “default-value” if $1 is not set.