- #MotionX Share: http://bit.ly/czeK #
July 2009
Exim Mail Server Commands
Those of you with Exim will sometimes needs to do some work on it – here’s a list of the commands which I find most useful:
If you want to see what exim is doing right now :
“exiwhat”
if you think you have queue problems then you can print a countof messages in the queue this will often be quite high – so it’s worth running it a few times over a couple of hours to see if you have a queue problem:
“exim -bpc”
If you want more information about what is in the queue then the following command will give you the count, the colume, oldest, newest, domain to be sent to and total summaries. The oldest and volume parts are often the most informative in this to help you see problem domains.
“exim -bp | exiqsumm”
Below are some commands to help you manage the queue – especially useful if you want to try to purge it or take action.
To tell exim to try to deliver things in the queue according to the rules for a queue run
“exim -q -v”
If you are blocked up with external mail you can tell exim to run the queue to deliver local mail only – this may help you get things such as notifications etc.. if they are delayed by other mail in the queue
“exim -ql -v”
If you have some problems with older mail (maybe spam related) – you can use the following to delete mail that over 7 days old (the time given is in seconds so just take one day 86400 and multiply it by 7)
“exiqgrep -o 604800 -i | xargs exim -Mrm”
There are many many other commands and other examples – some sites have longer lists, but these are all the commands I have needed (or variations thereof) for administrating my servers over the last 9 years.
Twitter Weekly Updates for 2009-07-19
- Am I getting old if I am seriously considering a trilby?? #
- #MotionX Share: http://bit.ly/CVKRl #
How to use crontab to schedule tasks in Linux
Another of the most useful tools in server administration is the Crontab – you use this to schedule jobs (programs) to run at regular intervals.
These tasks can be varied, from restarting servers, services – creating files, changing permissions, runing batch programs, deleting files etc…
Of course sometimes crontab is not the best solution as it can have several problems – in which case other choices are available – including writing your own – however we will cover that another time.
First a coouple of facts about cron:
- Cron has evolved a bit since inception but the basic principles are the same – old server admins are as good as new ones with this tool!
- Cron will run new jobs at most once a minute – that’s the smallest resolution you can have.
- Old systems used to wake up every minute and check for new work – the same as a simple replacement service might do – however this didn’t scale well when cpu power was low but users high on old mainframe systems – new systems still only execute once a minute.
- the cron service loads up any relavent cron files (which exist in users home directories or in /etc/cron.d/) and saves the information so it only needs to run when there is really jobs to run – when you edit the crontab it reloads it’s list so it doesn’t need to keep checking for changes – it’s important to edit it right!
- Even if a previous program hasn’t finished – cron can run it again or run more jobs – this can bring down badly configured systems! so be careful how you use it.
Generally to edit the crontab – which is where you would add things to run type in “crontab -e” – this will open it in your system editor (vim is my choice, but others can be used).
you will probably see some content – similar to this:
1 0 * * * shutdown -r now
This means that at one minute past midnight the server will reboot (execture the immediate shutdown and restart command with no delay) each day. The * are wildcards saying that the instruction should run no matter the criteria of that column (if it’s all * then it will run each minute).
The fields are the following: I recommend pasting this in the top of your crontab file – the # at the start mean it will ignore the entries.
# .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * *
Remember if the program has output you can store it in a file the same as you can on the command line – just type ” > /var/log/logfile”
in the entry after the command and it will log output to the file in question.
Twitter Weekly Updates for 2009-07-12
- Not enjoying having a bad back today! #
Using Grep to find a string inside a file (Linux)
Grep is a tool that is used often by system administrators – including myself, however I often have to double check the syntax online – as a result this post is to help me find out how and you of course.
first I recommend to change to the directory that you think or know the file containing the text is in:
- To find the string michael in any file type “grep michael * #this will return a the files if any are found within the directory
- To find the string michael in any file and search recusively in directories under where you are type “grep -R michael *”
Grep is one of the best tools available to an administrator especially for checking log files out and finding regular patterns.
Adding a new swap partition – Linux
I realised after my previous post I realised that it would be worthwhile talking about adding a new partitition.
The first thing you need – or I assume – is that you have a separate hard-drive which is not active (mounted) or can be unmounts using the standard umount command.
We assume the device is sdc (it could be sdb, sda, hda1 etc..).
- Ensure the drive is unmounted – turn off any swap already on it with swapoff (or if it’s clean of swap partitions then you can ignore swapoff)
- type in “parted /dev/sdc” This loads the parted prompt which allows you to manage the disk.
- enter “print” to view details of any existing partitions and free space.
- once you have decided the size you need (at minimum I would recommend match your RAM) type “mkpartfs part-type linux-swap start end” Where for the start and end match the start point available in the print command and ending a number x megabtes above i.e. if the start point is 1024 then the end point would be 5120 for a four gigabyte partition (4096)
- once done type quit to exit parted. The new partition will have been given a number e.g. sdc2 (or higher if others exist)
- all that needs doing is to format the partition “mkswap /dev/sdc”
- to enable it’s the same process as for the file – “swapon /dev/sdc”
If you want to make it work each boot – then edit the fstab using
vi /etc/fstab
add to the bottom: (press insert to enter edit mode)
/dev/sdc2 swap swap defaults 0 0
then press escape and shift-Z shift-Z
as before you can check to see if it’s been added by using
/proc/swaps
Twitter Weekly Updates for 2009-07-05
- #MotionX Share: http://bit.ly/X1W9l #
- #MotionX Share: http://bit.ly/3wUqdL #
Adding Swap Space without a partition – Linux
We had a problem on one of the servers which I help administer. Every now and again RAM usage would max out and SWAP would then be used – this would sometimes max out and bye bye server, normally this happened for only a few seconds and all was fine – however if it lasted more then when SWAP ran out – the server ground to a halt and needed a manual restart.
The server in question is quite busy – but only had 512Meg of RAM (this has since been rectified) historically as it wasn’t that busy at first several years ago has slowly grown as websites on it have grown in popularity and databases have grown.
So an immediate fix was required – it had a swap partition – couldn’t create a new one, it would mean downtime as we are using the hard-drives!
So added a swap file – here’s how to do it:
- Change to a directory (on a partition) where you have lots of space – e.g. /home “cd /home”
- Create a file swapfile using dev null – the following command will create a 4meg file: “dd if=/dev/zero of=swapfile bs=1024 count=4194304”
This creates an empty file called “swapfile” with a block size of 1024bytes and creates 419304 (to get the size do 4194304 / 1024 then divide by 1024 to get the size in gigabytes). - chmod it so it can be used “chmod 600 swapfile”
- format the file to a swapfile type so the system can use it “mkswap swapfile”
- In order to use it – turn it on “swapon swapfile”
At the end of this if yo do the following “cat /proc/swaps” to see your swapspace. It’s now larger by a lot and hey presto. Of course a long-term fix has to be more ram if possible or tweak your setups! (or a new server!)
This doesn’t get setup to activate on boot – mainly because I didn’t need this – a temporary fix and therefore didn’t want todo this as the RAM would be upgraded soon, but if you need more memory – and don’t mind it being slow for stability then this is a possible solution.