- 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.
Twitter Weekly Updates for 2009-06-28
- #MotionX Share: http://bit.ly/2U2nv #
R-U-ON IPhone app – Server Monitoring
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).
Twitter Weekly Updates for 2009-06-21
- Been out driving fast cars as a reward for hard work – thanks http://www.iknow-uk.com pics are at http://www.ihelm.org.uk/iknow_a_lotus/ #
- #MotionX Share: Segway route!! http://bit.ly/46vEx #
- I'm iphone 3.0's MMS here we are… nothing else seems to have changed really – couple of my apps may be obsolete now though! #
Iphone 3.0 OS update – initial thoughts
After waiting and hitting the Check for Updates button over and over again – at 7pm BST it finally arrived.. queue the 200+ MB download and the wait…
Once downloaded the update I had to wait for it to transfer the files – then it rebooted – great stuff… until the emergency call slider appeared – hmm – nothing happened – left for 20 mins – nothing happened. Odd..
Undock, redock – restart – still the same how odd. Time for the old fav – Turn off….. wait 5 mins….and turn on… and hey presto it worked.. So not the most smooth of updates – but nothing I am not used to.
Right first impressions.
It’s fast… Wayyyy fast, my Iphone is overloaded with apps – I mean really overloaded – we are talking 9 pages or so full of apps… and now it’s fast.
Switching between native things such as SMS , phone and dock is great – the hidden page to the left (spotlight) for searching is great… though maybe not too useful for me – I don’t store documents on the phone afterall.
MMS works with O2 and is brill 🙂 about time – not got anyone to send me one yet – but me sending works – so that’s a big plus – suspect it costs me though, need to find out from O2.
Audio recording – brilliant, had an app to do it before – but this actually is higher quality – and the app tended to get confused if interrupted – this works in the background! so you can do things and it’s still recording – excellent!
Bluetooth pairing with headset – AT LAST – my old old phone could do this – and now my iphone can too – no more cables to listen to things I can wear my nice headphones and get the sound – the quality is good too – better than most pairings!
All in all brilliant – now all I need is the new apps (tom tom??) and video recording – which we know the phone can do if jailbroken – so come on – I don’t need high quality – I just need to be able to record my daughter playing sometimes!!
Oh and on itunes it looks like I can buy movies an series.. seems pretty good, what if my space is limited and the download time seems a bit excessive.. we will see.
rm Argument list too long.. Linux Huh? moment.
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!