phirebird

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
Then change the mode of the file to allow execution:
[root@nas01 /]# chmod a+x dobackup.sh
[root@nas01 /]#
And then create the second file backftpscript (the FTP script):
open -u <ftp username>,<ftp password> <ftp host>
mput /back/*.tgz
bye
That’s it – you’re good to go! Just execute /dobackup.sh and it’ll tar everything and then upload it to the specified FTP server.

Here’s an explanation as to how it works and line-by-line what’s going on:

rm /back/*.tgz
Remove last nights backup! (or traces of any others)

d=$(date +%y%m%d)
Grab todays date (in the format yymmdd) and stuff it a variable ($d)

tar cvpzf /back/back$d.tgz –exclude=/proc –exclude=/lost+found –exclude=/back –exclude=/mnt –exclude=/sys /
Create an archive, make it Verbose, Preserve the permissions, filter the archive through gZip, call the File /back/back$d.tgz (e.g back101022.tgz for 22nd Oct 2010).  Exclude from the archive useless stuff like /back (the backup dir itself), /sys, /mnt, etc. And finally the target of the archive, /

lftp -f /back/backftpscript
lftp is like the ftp command, but with a lot more functionality and protocols. Probably warrants a how-to of its own, but needless to says it’s a lot more useful for use in situations like these. This particular line starts lftp and runs our ftp script, backftpscript. The contents of which are:

open -u <ftp username>,<ftp password> <ftp host>
Pretty self explanatory. Open a connection to <ftp host> and login as <ftp username> using the password <ftp password>

mput /back/*.tgz
After we’ve connected, upload (or put) all the .tgz files from our local /back directory

bye
Bid farewell and drop the connection (in a nice, polite sort of way)

Need this to run on a nightly basis? Take a look at my other how-to on cron jobs

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

It’s been a while, but here’s a quick how-to on creating a new file system and mounting on a Linux box.
My scenario was a 512MB CF card as an IDE slave – so /dev/hdb (b being the second IDE disk) – with no existing partitions, and create a mount point of /back (for backup purposes).

Here’s how:

[root@nas01 /]# fdisk /dev/hdb
Command (m for help): d
No 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): n
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-993, default 1): <hit enter>
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-993, default 993): <hit enter>
Using default value 993
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

[root@nas01 /]# mkfs.ext3 /dev/hdb1
mke2fs 1.41.8 (11-July-2009)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
125488 inodes, 500440 blocks
25022 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
62 block groups
8192 blocks per group, 8192 fragments per group
2024 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@nas01 /]# mkdir /back

[root@nas01 /]# mount /dev/hdb1 /back

[root@nas01 /]# df -m
Filesystem           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 /]#
If like me you want this to mount every time that you start up – just edit /etc/fstab and tag on a new line:

/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

Right. Just thought I’d chime in with information on offers of free Wii points cards and codes.

Unless given away by a third party as a gift, they simply don’t exist! Even as gifts, they cost a significant amount of time and money and only run for a short period of time. The only ‘genuine’ offer I’ve seen is where a guy had to sign up to a dating site – even then, the benefit to the company is obvious. If I’m wrong though, please do drop a comment below to tell everyone about it!!

Buy cheap Nintendo Wii Points Cards from Amazon

Points cards are available cheaply enough from Amazon UKAmazon 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 :)

  1. Intel PRO/100 (Earlier version)
  2. Intel PRO/100 (Newer version – doesn’t work with some older card)
  3. Intel PRO/1000
  4. Dlink DFE-650 (PCMCIA)
  5. Realtek 8029
  6. Realtek 8139 (but covers most of the 8100 range)
  7. BroadCom B57xx
  8. 3Com 10/100 MiniPCI (early Thinkpad)
  9. 3Com 3C90X (3C905, etc)
  10. Dlink DFE-530TX
  11. Realtek 8169 (As used by NetGear GA311)
  12. DEC Digital DC21140 (As emulated by Microsoft’s Virtual PC)
  13. AMD PCNet (As emulated by various flavours of VMWare)
  14. Accton/SMC EN1207D
  15. Generic NE2000 compatible (it’s worked on a few oddball cards!)
  16. SIS 900
  17. SMC 1211
  18. Dlink DFE-670 (PCMCIA)
  19. National Semiconductor DP83815
  20. Broadcom Netlink 4401
  21. 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:

PROTINI [DRIVERNAME] <IP Address> <Subnet mask>

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:

http://www.phirebird.net/files/mnbd.exe

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:

  1. Open the protected document in Word as normal.
  2. File/Save As…
  3. Select ‘Rich Text Format (RTF)’ from the ‘As Type’ drop-down list box and save it.
  4. Close Word
  5. Open Notepad (Start/Programs/Accessories/Notepad)
  6. Open your RTF file in Notepad
  7. Do a text search for ‘password’. It should return something like:
    {\*\password 5edc3b9c}
    (Obviously your password data will be different!)
  8. Delete this entire section, save it and close Notepad
  9. Open the RTF document in Word and hit ‘Unprotect’. If you get a password dialog box – just leave it blank.
  10. 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:

http://support.ntp.org/bin/view/Servers/WebHome 

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 tunnel

phbrtr#

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:

  1. Fire up “Active Directory Users & Computers”
  2. Locate the user and look at the objects properties
  3. 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.
  4. 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

 

 

Next Page »

phirebird