Schedule a job under Linux using cron
My last post was for a backup script that tar’ed up an entire Linux box (with the exception of some useless directories) and then uploaded it to an FTP server. Useful stuff, but a pain if you have to run it yourself manually every day! Enter, cron.
Cron is the daemon that executes commands according to a set schedule, and crontab is the utility used to manipulate it. To add a job, login as root and issue the command crontab -e. You’ll be presented with an editor for you to add the new job. The format the new line will need to format is as follows:
* * * * * command - - - - - | | | | | | | | | ----- Day of week (0 - 7) (Sunday=0 or 7) | | | ------- Month (1 - 12) | | --------- Day of month (1 - 31) | ----------- Hour (0 - 23) ------------- Minute (0 - 59)
So, if we wanted our backup script (located at /back/dobackup.sh) to run at 10pm every night, you’d insert:
0 22 * * * /back/dobackup.sh
Save and exit (as you’re in vi, that’s the key sequence: escape : w q enter), and it’ll be added to your crontab. To check, issue: crontab -l
Did you find this hint useful? Or are you wondering how to learn more? Well, here’s a few books that I’ve found useful over the years:
![]() Linux Command Line and Shell Scripting Bible |
![]() Linux: The Complete Reference, Sixth Edition |
![]() Linux Pocket Guide – Essential Commands |
![]() Linux All-in-one Desk Reference |
Backup a Linux box through FTP (push) and tar
Another quick Linux how-to. This time how to backup up an entire box using into a tar archive and push it to an FTP server. In my case, this ran every night and the FTP server was the central tape backup unit.
It’s a good idea to create yourself a separate directory to store the backup shell script and FTP script. For want of a better name, I created /back (10 out of 10 for originality, right?). In there, first create the backup script dobackup.sh:
rm /back/*.tgz
d=$(date +%y%m%d)
tar cvpzf /back/back$d.tgz --exclude=/proc --exclude=/lost+found --exclude
=/back --exclude=/mnt --exclude=/sys /
lftp -f /back/backftpscript
[root@nas01 /]# chmod a+x dobackup.sh[root@nas01 /]#
open -u <ftp username>,<ftp password> <ftp host>mput /back/*.tgzbye
Are you wondering how to learn more about Linux? Well, here’s a few books that I’ve found useful over the years that might just help you more:
![]() Linux Command Line and Shell Scripting Bible |
![]() Linux: The Complete Reference, Sixth Edition |
![]() Linux Pocket Guide – Essential Commands |
![]() Linux All-in-one Desk Reference |
Creating and mounting an ext3 partition
[root@nas01 /]# fdisk /dev/hdbCommand (m for help): dNo partition is defined yet!(Note: If you’ve got an existing partition on the drive, d will remove the partition and you’ll get a message like “Selected partition 1″. If you’ve got any additional partitions, d them too)Command (m for help): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 1First cylinder (1-993, default 1): <hit enter>Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-993, default 993): <hit enter>Using default value 993Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[root@nas01 /]# mkfs.ext3 /dev/hdb1mke2fs 1.41.8 (11-July-2009)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)125488 inodes, 500440 blocks25022 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=6763315262 block groups8192 blocks per group, 8192 fragments per group2024 inodes per groupSuperblock backups stored on blocks:8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409Writing inode tables: doneCreating journal (8192 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 37 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@nas01 /]# mkdir /back
[root@nas01 /]# mount /dev/hdb1 /back
[root@nas01 /]# df -mFilesystem 1M-blocks Used Available Use% Mounted on/dev/hda1 1930 741 1090 41% /tmpfs 1980 0 1980 0% /dev/shm/dev/hdb1 474 11 439 3% /back[root@nas01 /]#
/dev/hdb1 /back ext3 defaults 1 1
Did you find this hint useful? Or are you wondering how to learn more? Well, here’s a few books that I’ve found useful over the years:
![]() Linux Command Line and Shell Scripting Bible |
![]() Linux: The Complete Reference, Sixth Edition |
![]() Linux Pocket Guide – Essential Commands |
![]() Linux All-in-one Desk Reference |
Free Nintendo Wii Points cards / codes
Points cards are available cheaply enough from Amazon UK, Amazon USA and even on eBay (although your mileage with eBay will depend on the seller). So why bother spending countless hours chasing ghosts?!
Oh, one last thing to remember if you’re still searching for freebies – codes can usually only be used once!!
MS-DOS boot disk with network support
Here’s a little gem that I seem to be perpetually working on! An MS-DOS boot disk with MS-LAN Manager, various NDIS network card drivers & DOS TCP/IP support. Currently, the following network cards are supported, but it’s really easy to add your own – as long as you’re not afraid of batch files
- Intel PRO/100 (Earlier version)
- Intel PRO/100 (Newer version – doesn’t work with some older card)
- Intel PRO/1000
- Dlink DFE-650 (PCMCIA)
- Realtek 8029
- Realtek 8139 (but covers most of the 8100 range)
- BroadCom B57xx
- 3Com 10/100 MiniPCI (early Thinkpad)
- 3Com 3C90X (3C905, etc)
- Dlink DFE-530TX
- Realtek 8169 (As used by NetGear GA311)
- DEC Digital DC21140 (As emulated by Microsoft’s Virtual PC)
- AMD PCNet (As emulated by various flavours of VMWare)
- Accton/SMC EN1207D
- Generic NE2000 compatible (it’s worked on a few oddball cards!)
- SIS 900
- SMC 1211
- Dlink DFE-670 (PCMCIA)
- National Semiconductor DP83815
- Broadcom Netlink 4401
- VIA 10/100 ‘Rhine’
Originally, this was written for a set of floppy disks (which is why you have the option to change your computer name), but currently I use it in the lab to PXE boot over the network (Google tFTPd32 and pxelinux! I might write a how-to on this one day).
Everything should be pretty self explanatory – the machine boots, starts DOS, loads himem, a RAM disk and a few other drivers, extracts the base network stuff from net.zip to the ramdisk, throws up a prompt asking what network card you’ve got (yes I could autodetect – but pciscan or equivalent hurt the footprint – this is meant for a regular 1.44MB floppy, remember!), extracts the NDIS drivers from the relevant zip, creates protocol.ini and system.ini to match your chosen card, starts the network, grabs an IP with DHCP, and asks for a username/password. Job done!
If you’ve not got a DHCP server on your network (if so, get into the 90′s!) then take a look in selcard.bat – and update your chosen card. I wrote protini.exe in VBDos and added support to handle parameters (IP and subnet). Just change the line to follow the format:
As for adding drivers for new cards – again, just edit selcard.bat and place a zipped copy of your NDIS drivers into the \NICs subdirectory.
You can download a copy of the disk images here:
http://www.phirebird.net/files/mnbd.imz
or a self-extracting disk image:
Use it at your own risk, blah, blah, if your wife divorces you, blah, blah, don’t blow up, blah, blah, not liable, blah, blah, etc, etc – insert the rest of a usual disclaimer here.
Why would you use this? Well, I’ve found it useful for many reasons – mostly when trying to take/apply Ghost or PQDI images to/from PC’s and servers. But you wouldn’t be reading this if you didn’t already have a use for it – right?
How to remove passwords on Microsoft Word documents
Ok, so you’ve found yourself in the situation where you can’t update an MS Word document that you created years ago and can’t remember the unprotect password! D’oh! Well, don’t be drawn in by premium/commercial solutions to this problem – when you can solve it for free! Forget dictionary attacks, you weren’t silly enough to use a plain word - right?! Also, forget cracking by brute force – because you don’t have the time!
Simply follow these steps:
- Open the protected document in Word as normal.
- File/Save As…
- Select ‘Rich Text Format (RTF)’ from the ‘As Type’ drop-down list box and save it.
- Close Word
- Open Notepad (Start/Programs/Accessories/Notepad)
- Open your RTF file in Notepad
- Do a text search for ‘password’. It should return something like:
{\*\password 5edc3b9c}
(Obviously your password data will be different!) - Delete this entire section, save it and close Notepad
- Open the RTF document in Word and hit ‘Unprotect’. If you get a password dialog box – just leave it blank.
- Now, do a ‘Save As’ again – but this time save it as a regular word document.
All done!
Is this legal? Well, I’d say so. It’s your document – and not your fault that you forgot the password! I think a slap around the back of the head is due though!
Disable movie/video thumbnail preview under Windows XP
Rather annoyingly, the explorer.exe process under Windows XP can sometimes hang, stop responding, crash or just plain terminate/close itself while it tries to display video/movie thumbnails in any given folder.
The reason for this can be a multitude of issues – like a dodgy codec, etc – and seems to be rather in-discriminant as to which file type it decides to screw up with (AVI, MPG, WMV, ASF, etc).
To get around this problem though, it is possible to easily disable this feature. Either fire up a command prompt or execute this straight from the run dialog box:
regsvr32 /u shmedia.dll
And if you want to re-enable it again at a later date:
regsvr32 shmedia.dll
Now, the only knock-on effect is that you’ll no longer be able to see summary information in the file properties. In my opinion though, it’s a small price to pay!!
Configure NTP time server synchronisation on Cisco routers
Maybe you want an accurate time source on your internal network for your servers to sync against. Or maybe you just want your Cisco box to report the correct time! In either case – you’ll need NTP.
First, we’ll sync the router time against another NTP time source. It’s as easy as specifying an IP:
phbrtr#conf t
Enter configuration commands, one per line. End with CNTL/Z.
phbrtr(config)#ntp server <IP address>
phbrtr(config)#exit
phbrtr#
Incidentally, you can find a list of public NTP servers at:
To tidy things up, you might want to prevent NTP synchronisation attempts on a per-interface basic. To do this, you can ‘ntp disable’ on the relevant interface(s):
phbrtr#conf t
Enter configuration commands, one per line. End with CNTL/Z.
phbrtr(config)#interface fa1/0
phbrtr(config-if)#ntp disable
phbrtr(config-if)#exit
phbrtr(config)#exit
Finally, heres how to check that everything’s working as it should:
phbrtr#sh ntp status
Clock is synchronized, stratum 2, reference is 129.6.15.28
nominal freq is 250.0000 Hz, actual freq is 250.0005 Hz, precision is 2**24
reference time is CE89F9F3.27B5E326 (21:21:55.155 GMT Wed Oct 21 2009)
clock offset is -13.4327 msec, root delay is 99.40 msec
root dispersion is 21.27 msec, peer dispersion is 7.83 msec
phbrtr#
Are you looking to learn more about Cisco equipment? Well, here’s a selection of a few books that I’ve found useful over the years:
![]() Cisco: A Beginner’s Guide |
![]() CCNA – Cisco Certified Network Associate Study Guide |
![]() Cisco Networking for Dummies |
![]() Cisco IOS in a Nutshell – O’Reilly |
Terminate current VPN sessions on Cisco router/ASA
Many a time I have to kick remote users off a Cisco router / ASA box. This depends on your configuration – but here’s how to close one or all VPN user sessions on the PPTP setup we created in an earlier how-to. First, we’ll check to see who’s online:
phbrtr#sh vpdn session
PPTP Session Information Total tunnels 1 sessions 1
LocID RemID TunID Intf Username State Last Chg Uniq ID
32 32768 37 Vi3 user estabd 00:00:18 31
phbrtr#
That pesky user!! Lets disconnect him..
phbrtr#clear vpdn tunnel pptp id 37
Starting to clear the tunnel
phbrtr#
Note here that we’ve used the TunID from the previous command (in this case – 37). Another quick ‘show vpdn session’ (or for the lazy: ‘sh u’) will show that your user has disappeared.
If you’ve got a lot of users, looking up their id and clearing can be quite tedious. To clear ALL PPTP sessions:
phbrtr#clear vpdn tunnel pptp all
Clear all PPTP tunnels? [confirm]
Starting to clear the tunnelphbrtr#
Simples!
Are you looking to learn more about Cisco equipment? Well, here’s a selection of a few books that I’ve found useful over the years:
![]() Cisco: A Beginner’s Guide |
![]() CCNA – Cisco Certified Network Associate Study Guide |
![]() Cisco Networking for Dummies |
![]() Cisco IOS in a Nutshell – O’Reilly |
Add an email address alias to an Exchange account
Just a very quick one. Most people probably know this already – but just to show how to add/manage email address aliases:
- Fire up “Active Directory Users & Computers”
- Locate the user and look at the objects properties
- In the Email Addresses tab - you’ll have a list of various entries. All of the ‘SMTP’ type are email addresses / aliases. The one in bold is the primary account.
- To add a new alias: click New, select ‘SMTP address’, click OK and enter the desired email address.
Simples!
Did you find this hint useful? Are you looking to learn more about Exchange? Well, here’s a few books that I’ve found useful – have a goosie!
![]() Microsoft Exchange Server 2003 Training kit |
![]() Mastering Microsoft Exchange Server 2003 |
![]() Configuring Microsoft Exchange Server 2007 Training Kit |
![]() Microsoft Exchange Server 2007 for Dummies |














