Hi Guys, If you have mail command available then using it in a shell script is not that difficult, If a guy like me can do it anyone can I guess because I am not a native Linux man :) Anyway lets check how to do it I saved above as jasmail.sh As you will notice that I am using the heredoc syntax in the above script. There are sometimes that you want to send custom email messages so accepting the message from command line param makes sense so here is a little modification to the above script so that you can make use of it if you think that it could be useful Alternative So as you can see that in the MSG container I've use ${1} bit which means that the first command param becomes my email message as shown below That makes sense I guess. This is just a basic bash script, the Linux Gurus reading this post will have more to share if they wish to leave their feedback. One last bit, do not forget to give execute permission to the current user else you will not be able to use above bash script. I hope this will help or at least give you an indicator that will serve towards your final result/requirement Cheers … [Read more...]
bash script to monitor apache httpd service and automatically restart/kill if it hangs or not responsive
Hi Guys, My Apache Web-server was playing up a little bit so until I found the cause of it my priority was to keep it up and running so I wrote a bash script to keep an eye on httpd crashes Lets check it out First up is to pick a script name and named it as httpdmon.sh and it is stored in my /home/jas/ directory CronJob Next I would just set a cron job so that it runs every minute and restart/start the service if required. Basic Script Above script is good and as you can see that I am using curl to shoot a request to my local website and if the request times out i.e. after 5 seconds then an attempt to restart the service is made Now thats Ok but I would also like to be notified about it and also would like to force kill httpd process if for some reason it hangs A little bit more added to above script As you can see that above will send me a message, you can replace mail command with sendmail etc its up to you. Running that solved few of my issues until I figured out what is causing httpd to crash. If I found something interesting I will be sharing it with you guys. Please note: I am not a Linux Advanced user but just knows enough to do some basic to intermediate things. If you have something to add to would like to improve above script please leave your comments as it would help others. Cheers, … [Read more...]
Linux How to get total directory size
Hi Guys, Just a quick one here, If you want to know size of a directory/folder you can use du command which is short form to disk usage You can cd to that directory and run this command Forget about the fact that I am logged in as root, I was just doing some weird things. Option 1 Option 2 or Now the above commands will print fill directory size but just in case you want to list sub directory size separately then this is how you do it You can also specify directory path as shown below Above will work on /home/web folder You can also get quite interesting but if all depends what you are trying to do just type to see what else you can do here is a quick link to man page available through http://unixhelp.ed.ac.uk/CGI/man-cgi?du Above listed is just to give you an indicator Linux is so wide with its commands that there could be another 10s of combination to achieve above results but I am not not aware of those 10s so I rely on the above mentioned commands :) I hope this helps Just in case you would like to add something to this post or want to correct improper use of a command please leave your comments Cheers … [Read more...]
Basic Shell script to automatically start NodeJS if for some reason it stopped
Hi Guys, Well this one is a really basic example of a shell script that I used before in one of my production NodeJS website called http://icompressjs.com Here is the bash script that I wrote to monitor my local node install as you can see that I am running Node on port 8080 and I am using curl to send a request to my node server. If response is 200 that is good and it will print "All Working well" else it will try to start NodeJS server You can also plugin another line to send email to you when a server is launched again. Something like this mail -s 'Subject' [email protected] < msg.txt put above line just under echo "Launching" Now the final step is to cron this our bash script. I named it as node_monitor.sh You will have to give your local user rights to execute this script, after doing that you are able to cron it as shown below Above lines says that every 5th minute run node_monitor.sh If the response is ok i.e. 200 then nothing will be done else there will be an attempt to start NodeJS server again You can improve this script with better error handling but for what I was trying to do this was sort of enough I hope this helps Cheers … [Read more...]
Linux Count lines in file and Sum count
Hi Guys, To start with I am intermediate user of Linux and use RedHat at work and Ubuntu at home. I had this job where I have to search my apache server logs for some "text". Count the number of lines that have this "text" in them. Well I know basic shell scripting so I just used a bit of basic commands to get what I wanted. If you know other better solution please leave yours in comments. So DIRPATH above holds path to my access logs directory and I am iterating over to get line count of files one by one and my COUNTTOTAL variable holds the overall count. Above example show to count all lines and summing the output. In the example below lets make a slight change and search for a string "abc.com" and see how many lines have this string present. As you can see that we now are searching text "abc.com" in a file and piping the output to wc command adding the output to our global variable COUNTTOTAL and printing it using echo command. you should change DIRPATH to suit you. You can use the same fundamentals to create a dynamic list of file e.g. count the number of lines for files that are younger than 30 day, and iterate over them. We have used the following command in our shell scripts and each of the one have link to their manual page grep wc cut As my mate David Overton pointed out that above can be achieved without a script so here are our shell commands to do exactly the same thing. I think I am just stuck with scripting mind frame :) First command (equivalent to first script): Second command (equivalent to second script) : I hope that this helps. If I made any mistake please let me know. Cheers … [Read more...]
Cpanel: Install mod_cloudflare
Hello, Now that I've put my site on CloudFlare, hopefully you will see a performance boost and site load time should drop. Guys at Cloudflare directed me to read this document which I think was sort of a kick start on "How To with cloudflare?" You can read that document here http://blog.cloudflare.com/cloudflare-tips-recommended-steps-for-new-use This document helped me a lot in understanding the configurations and how to use CloudFlare control centre. You must be aware that CloudFlare act as a proxy to your server thus all the IP addresses hitting your server would be CloudFlare's IP addresses. Your access logs will start looking weird. You should also read these documents https://cloudflare.tenderapp.com/kb/why-do-i-see-cloudflares-ips-in-my-server-logs-or-site-logs Now this post just tackle one specific problem i.e. How to install mod_cloudflare under CPanel Follow these steps Use putty or similar tool to connect to your server using SSH. Goto your home directory or goto /usr/local/src We will download the source code for mod_cloudflare now with the following command Above step will download file called mod_cloudflare.c We will now use apxs (Apache Extension Tool) to install our mod_cloudflare with the following command Make sure that you have not changed your working directory Now we will restart our Apache service with the following command OR Final step would be to update Apache Configuration and is done with the following command Make sure that there is no error from any of the above step. If you are not a system administrator then you should avoid doing it. But if you are a a techie and are confident enough then go ahead and do it. I also have compiled these instruction from elsewhere and did it without any issues. You may have to ask your hosting provider to do it for you on your server just in case you don't have root access to your … [Read more...]
Ubuntu Download youtube videos as mp3
Hello, In my last post I highlighted how you can download youtube videos using a great tool called youtube-dl In this post we will be covering a few things. Downloading youtube videos and later converting them to mp3 Downloading videos directly as mp3 We will be making use of ffmpeg and youtube-dl for our case. Lets go Preperation Just so that you know that you will need to install youtube-dl first on your Ubuntu box. If you haven't read my previous article please read that from here http://jaspreetchahal.org/ubuntu-12-04-download-youtube-videos-using-youtube-dl/ You will also need to install ffmpeg. You can install it using the command below Downloading video from youtube and converting them to mp3 using ffmpeg Lets download a video from youtube now. Considering that you are in /home/user/videos directory and you have write permissions to this folder, run this command Your video will now be stored under /home/user/videos as C-2MmguSO4w.mp4 You can also specify a file name when using youtube-dl as shown below Depending on your download speed it can take a while to download this video. Just in case if you got error saying "Unable to download" then you would like to read my previous post. Now we have C-2MmguSO4w.mp4 to work with. Lets convert it to mp3 The command The above command will convert our mp4 file to a mp3 -ab 192000 in above command means that our mp3 should be encoded at 192Kbps for great quality -vn means that do not include video -i means input file name To know more about ffmpeg command read more here http://linux.die.net/man/1/ffmpeg Downloading videos as mp3 using youtube-dl Now that we have seen how to mix ffmpeg and youtube-dl together to convert to desired format. We can do pretty much the same stuff with youtube-dl by itself. Allow me to show you how this is done Use this command And that's it your video will be … [Read more...]
Ubuntu 12.04 Download Youtube videos using youtube-dl
Hello, Now that I have finally settled on Ubuntu as my Linux distro at home, there is heck of a stuff to learn. Well one of the things that I used to do on my previous Linux distro was to download Youtube videos and convert them to other formats using ffmpeg. This post is all about showing you how to get running using a cool script called youtube-dl Just so that you are aware youtube-dl tool can use ffmpeg, so gone are the old days. This tool has grown to much of my liking now. Lets first of all install youtube-dl This command will install youtube-dl downloader tool. Now try this command Your video will start downloading right away and will be stored in current folder (if you have write permission to it) by name ckYwfP9-pLE.mp4 As you can notice that video file name is exactly what query string param v's value is. Hang on but I got a "Unable to download video" error Well this is because you are running old version of youtube-dl installed, I guess the repo source does not get modified with each change. There is a easy way to update youtube-dl as shown below -U switch will check and update youtube-dl Try to download the above video again. Ta! Da! and its downloading correctly now. If not check your permission on folder that you are trying this command from. Advanced options For more advanced option you can always read man page of this tool by using the command below In my next article I will show you how to download a youtube video as mp3 and some more examples. I hope that this helps. If you have anything to add please leave your comments. I can compare your feedback to food I eat. I love both :) Cheers … [Read more...]
CPanel Apache error_log and access_log location and location for mySQL logs
Hi Guys, So we all know that CPanel makes our life easier in many ways. Guys like me who are not Linux power users but more of intermediate level users love CPanel. I do! Well there is a strange overlapping when we have full root access to our VPS or Dedicated server. CPanel does help with many things and some things we like to do traditionally. For me error_log and access_log are one of those that I love to watch from my lovely shell. Now to get to the location of your log file you can do few things. You can get your access log location from apache configuration for each domain, but let me give you pointers to where these files are located Apache access_log files Complete apache access log can be found here You can use command like tail to print last few lines of access log. Apache Domain specific access_log file If your server handles multiple domain requests then most likely they all have their own individual access_log files these can be located here Once again you can use tail command to check out last few lines in domain specific log file Apache error_log These log are more frequently visited than the access_log ones, one reason is that all your ERRORs and Exceptions that Apache came across are logged in this file. Thus we can find a problem and issue a fix. The location for error_log files is While fixing a problem I generally leave this command running to get the up2date log data mySQL Logs file with CPanel you can get hold of .err file here Configuration file can be located here Apache Configuration File location httpd.conf can be found here You can viit like I hope this helps Cheers Advertisement … [Read more...]
Rsync to non standard SSH port
Hi Guys, While I was configuring my new VPS box I realized that it may not be a good thing to keep port 22 as default for SSH connections. Thus I decided that it will be port 2224 for SSH communication. I love putty as all others, I am not a typical system admin but I love playing around with few things. CPanel is one of those things. One of the software that I use too often is rsync You can become expert user of rsync by just following this manual http://linux.die.net/man/1/rsync anyway this is not about explaining what rsync is, you are reading this post because you already know what rsync is. Now coming back to my original point, so I configure my VPS disabled my port 22 and enabled my port 2224 for SSH communications, If you don't know how I did this here is a tip for you Uncomment the line and put your desired port in as shown below You will need to allow your firewall to allow port 2224 for incoming All done then restart your sshd service as Now I wanted to rsync from my local server to my production VPS at port 2224 this is how I did it As you can see is that trick is to instruct rsync to connect to the non standard port that is done by this bit "ssh -p NEW_PORT_NUMBER" Above can be rewritten for port 2224 as You can add other flags if you wish, many a times we try to preserve permissions and owners at the target so that is one thing I always do else everything gets messed up. I hope this helps Cheers Advertisement … [Read more...]





JC WordPress Coupon Revealer Plugin Pro License
Australian Street Names with City, State and Display Names only, Single Server License
Recent Comments