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.
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
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.
Kick-starting an Iphone app review cycle, first up is one of the most useful app’s I have for server monitoring.
R-U-ON http://www.r-u-on.com/ is a great service, which has a free level and a paid. Personally I used the free service for several years, now I use the paid service.
The Iphone app works with both absolutely fine. Basically you create an account and then download a small program called an “agent”, this is set running or installed on your computer or server – these agents then connect to the r-u-on servers and send information.
You can get information about several things, most useful to myself is disk space, virtual memory usage, ram usage, cpu and load stats. If any of these exceed limits set (you can customise them). Critical failures can be notified by text message (theres a fee involved for this) which is absolutely essential.
The IPhone app simply connects to the r-u-on account and shows a summary, of your alarms (server’s which have exceeded a notification threshold – see the graphic below for this), or general server status – which hopefully is all green and show’s that all your servers are running well. You can also view your trouble tickets, personally I’ve never done this and have no real idea what it is.
The only thing missing from the app is the ability for it to run in the background, though of course the Apple SDK does forbid this – bah! however it would be great if it could or some kind of background notification system used (which I believe may be available in OS 3.0 but not 100% sure).
I recently had a little problem when deleting a store of spam e-mails off one of my personal servers.
Basically entering the standard death defying command of “rm -Rfv *” while in a directory (this will delete everything recursively – have fun), the system responded “Argument list too long” – cue the first “huh?” moment – I’ve used the command for years and years, never had a problem.
I did “man rm” to check I hadn’t had a “moment” and forgotten how to use it – nope.. . A little trawling came up with several people with the same problem but no really practical solutions. The problem occurs when you have too many files for the built in systems used by the rm command in the kernel – these are pretty old so have some limits that you don’t expect! – you can do this:
rm -Rfv a* then rm -Rfv A* – these deletes all files starting with a or A etc.. – very long and rather silly – so after thinking and thinking and muttering an old command came to mind 🙂 using a combination of find and xargs you can pipe a file on at a time so here we go – my favoured solution:
find . -name * | xargs rm -fv
This works fine – I suspect it will have a limit somewhere, but my server hasn’t hit it yet!
After several years of running different solutions on different servers I have found that ASSP is one of the best anti-spam solutions around.
However – after some time it still struggles and gets weaker, can anyone recommend any other systems that can work ALONGSIDE it (not replace).