Flipkart

Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Tuesday, July 2, 2013

lighhttpd dead but subsys locked

Recently I was assigned a work to run a .sh file from php script. This .sh file will execute some Linux commands to move the data from one server to another. After completion of moving part, need to restart the lighthttpd server to take all the changes updated.

This script is working perfectly when we ran from the command line but throwing error "lighhttpd dead but subsys locked" from php script. So I did debug and googled to find the problem and I found that issue with "Service restart" command.


At last I resolved the issue by changing from Service <service name> restart to Service <service name> stop and Service <service name> start individually

Wednesday, September 22, 2010

Install Adobe Reader (acroread) on Fedora 12 and Fedora 13

http://macintoshbrasil.com/2010/06/10/install-adobe-acrobat-pdf-reader-on-fedora-centos-red-hat-rhel/

Thursday, August 26, 2010

IEs4Linux (Fedora)

Open a terminal. Log in as root to install wine and cabextract:

yum -y install wine*
yum -y install cabextract

Logout and install IEs 4 Linux with your normal user account:

wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
tar zxvf ies4linux-latest.tar.gz
cd ies4linux-*
./ies4linux

Wednesday, June 16, 2010

Run Script From Cron

The cron man page defines cron as a "daemon to execute scheduled commands". This means you can run scripts every hour, or every day, or on the 13 of every month at 5:38am. Here is an example of a cron entry.
00 18 * * * /path/to/command
In a few short minutes you will understand what this command means.

Structure

The structure of a cron entry as seen above is quite simple when broken down. In the above entry there is five sections and a path to a PHP script. Here is how it breaks down
Minute Hour Day Month Day Command
Lets break it down further..
Minute
Minute of the hour, 00 to 59
Hour
Hour of the day in 24-hour format, 00 to 23
Day
Day of the month, 1 to 31
Month
Month of the year, 1 to 12
DayDay of week
3 chars - sun, mon, tue, or numeric (0=sun, 1=mon etc)
Command = The command you want to execute
The time is in twenty four hour time. So you may have guessed already that the 00 is the minutes and the 18 above is 6:00pm. The asterix character * is a wild card and means every. That is, every minute or every day, or every month. This means the script.php script would be executed every day of every month.
00 18 * * * /path/to/script.php

Crontab

The crontab is the command used to interface with cron. Within crontab command can be entered, editted or deleted. To enter into the crontab simply type:
crontab -e
This command will bring you to a vi console where you can create your cron entries. All the same rules that apply to vi apply in the editor. It is important to follow the examples here by using absolute paths to the script that is to be executed. This is because crontab does not have access to the system $PATH, so any system command also need have thier full path also. The path to a system command can be aquired using the which command. The $PATH is not available within cron, however, the $HOME variable is, so that when we need to execute a command or script from our home directory, this is available to us.
#which
mail /bin/mail

Set Crontab Editor

It is hard to imagine, yet there are still people out there who do not use vi(m). On most unix and unix like systems vi(m) is the default editor for crontab. This means when you type "crontab -e" at the command prompt, the crontab file is opened in vi(m). To alter this behaviour, the default editor can be changed or exported with the export command. Shown here is an example of changing the default crontab editor to joe.
export EDITOR=joe

Examples

We saw above how a script could be run at 6:00pm every night. But what is a script needs to be executed every 5 minutes. We could do something like this.
0 ,5,10,15,20,25,30,35,40,45,50,55 * * * * /path/to/command
This example shows how the time increments are seperated by a space, but we can have multiple values seperated by comma's. Of course, this is a lot to type out, so cron has a little shortcut syntax to achieve the same result.
*/5 * * * * /path/to/command
The previous examples show how to run every day or every whatever. But what if we wish to run a PHP script at 4:00am each Friday just before we go home.
00 16 * * fri /usr/local/bin/php $HOME/script.php
The above cron entry will shows 4:00pm every Friday (fri) and will execute the command /usr/local/bin/php $HOME/script.php. Note the use of the $HOME variable to show that the script.php file to be executed is within the users home directory. The path to the php executable however, must be an absolute path. There is more to cron than these simple demonstrations have shown. It is hoped that this is enough to get you up and scheduling tasks with the cron and the crontab. Just remember the sequence of times - Minute Hour Day Month Day Command

Backup MySQL Database With Cron

Database backup are a frequently performed task, usually a webmaster will begin this process after losing their data and realise that this needs to be done on a regular basis. This is an ideal situation where cron can be used. Database backups should be stored by date. That is, the filename of the SQL dump should be .todays_date.sql so a backup can be made from a given time and/or date. to achieve this, enter the following command in crontab
0 2 * * * /usr/local/bin/mysqldump -db_user -db_password db_name > /home/www/backups/dbname-`date +\%s`.sql

Wednesday, June 2, 2010

Finding a file with particular content

Ever known that you had written a function for something, but can't remember which file it was in?
  1. grep -iR myFunction ./  
"grep" is a program for printing out lines that match a particular pattern. You can provide it with some switches, like the "-i" for making it case-insensitive, and "-R" for making it recursive in my example. Then provide a pattern, and the path to search in (here I'm searching the current directory with "./"). This example will show the filename and the line in that file for any matches it finds to "myfunction" (case-insensitve because of the "-i").

If your projects are Subversion working copies, you may find that it's annoying to see results from the ".svn" directories. To exclude particular directories from the search, use the "--exclude-dir=" switch, for example "--exclude-dir=.svn".

Find / Replace in a Text File

Sometimes you have a big file, like maybe a database export, and you need to do some find / replace on it... but it won't open in any of your text editors, because your machine runs out of memory trying to open it! Well, here's a way around that, by using the command-line and a little regular expressions.
The way this works is to output the contents of the SQL script (or whatever file you're using), pipe it through a program called "sed," which is specifically form manipulating streaming content, and then redirect that output into the new file. Sound complicated? Well... I guess it is a little, but the command itself looks simple!
  1. cat original_dump.sql | sed s/faruq/Shaik/ > new_dump.sql  
The new part here is really the "sed" program. Basically what it's doing is taking input and matching the first pattern (in this case, my name, "faruq"), and replacing it with the second pattern (in this case, a shortening of my name, "Shaik"), then outputting that.

Restoring from a Database Backup (with GZip Compression)

So you’ve got a backup of your database (either using the method above, or some other way), and something has gone wrong and you need to restore, or you’re migrating it to a new server. You could use one of the other tools mentioned before, but in the example of phpMyAdmin, what if your database backup file is bigger than the allowed upload size? Well luckily, the command-line doesn’t mind.
The command to restore is very similar to the one for backing up. Firstly, without GZip compression:
  1. cat db_backup.sql | mysql -u mysqluser -p mysqldatabase  
We use the “cat” command to output the contents of the backup script, and pipe its contents into the mysql program. As you can see, the mysql program takes the same options as the mysqldump one does in section two.
Now if the script was GZip compressed, we can’t just output its contents into mysql, as it will be compressed data instead of a nice SQL script. So we do the following:
  1. gunzip < db_backup.sql.gz | mysql -u mysqluser -p mysqldatabase  
See, it's very familiar, just switched around a bit.

Wednesday, March 31, 2010

Beginning SSH on Ubuntu

Installing OpenSSH

The Ubuntu (and MacOS X) flavor of SSH is called OpenSSH, a free, open-source implementation of the ssh protocol. It consists of two basic components, an openssh-client and an openssh-server. SSH clients communicate with SSH servers over encrypted network connections.

The openssh-client software should already be installed by default on Ubuntu. If you want to be able to accept SSH connections as well as request them, you’ll need the server software as well. The easiest way to ensure you have both is simply to run:

sudo apt-get install openssh-client openssh-server

Using SSH to Log into a Remote Computer

Once OpenSSH is installed, you can login to a remote SSH server by using the ssh command:

ssh remoteuser@remotebox

where remoteuser is the username of the remote account you’re trying to access, and remotebox is the remote server’s hostname or IP address.

For example, if you know that your Kubuntu desktop box (now running openssh-server) has a user account named joebanks and that the IP address of that computer on your private LAN is 192.168.0.12, you could login remotely to that account from your Linux/Mac laptop by typing:

ssh joebanks@192.168.0.12

If you’re unsure of a computer’s local IP address, try running ifconfig on that machine. This will display the status of the active network interfaces, and the local IP address of that device will be listed after inet addr. It will most likely be in the form of 192.168.0.xx.

Or, if you’ve got a web hosting account that allows shell access (e.g., DreamHost) with a domain name like cooldomain.com, your syntax might look like:

ssh joebanks@cooldomain.com

Now, the first time an SSH client encounters a new remote server, it will report that it’s never seen the machine before, by printing the following message:

The authenticity of host 'remotebox (192.168.0.12)' can't be established.
RSA key fingerprint is 53:b4:ad:c8:51:17:99:4b:c9:08:ac:c1:b6:05:71:9b.
Are you sure you want to continue connecting (yes/no)?

This is just an extra security measure to ensure that you’re actually connecting to the machine you think you are. If you type yes (the most common response), you’ll see the following:

Warning: Permanently added 'remotebox' (RSA) to the list of known hosts.

Subsequent login attempts to this machine will omit the warning message. You’ll then be asked for the remoteuser’s password:

remoteuser@remotebox's password:

And after correctly entering it, like magic, you’ll be logged into the remote machine, and instead of your local machine’s command prompt, you’ll see the following:

remoteuser@remotebox:~$

And, voila! You can execute commands on the remote machine just as you would on your local box. To close the connection to the remote server, type exit, or use Ctrl-D.

Copying Files

To transfer files and directories from your local machine to the remote server and vice-versa, you’ll use SSH’s “secure copy” command, or scp. To copy a single file from your local machine to the server, use the following syntax:

scp file.txt remoteuser@remotebox:/directory

where file.txt is the name of a file in the current directory of your local machine, remoteuser@remotebox is the username and hostname or IP address of the server (just like in the above ssh examples, and /directory is the directory path on the server where you want your file copied.

For example, if you want to copy the local file.txt to the /home/joebanks/docs directory on the server you logged into above, you’ll run the following command from a local terminal session:

scp file.txt joebanks@192.168.0.12:/home/joebanks/docs



You can be as verbose as you want with the local and remote filenames and directories, even changing the filename in the process, like so:

scp ~/docs/oldfile.txt joebanks@192.168.0.12:/home/joebanks/docs/newfile.txt

To copy a file from the server to your local machine, use the following syntax:

scp remoteuser@remotebox:file.txt /local/directory

where remoteuser@remotebox is the username and hostname or IP address of the server, file.txt is a file in the /home/remoteuser directory, and /local/directory is the local directory path into which the file will be copied.

Again, you can be as verbose as necessary, for example:

scp joebanks@192.168.0.12:~/docs/newfile.txt /home/joe/downloads

Copying Directories

To copy an entire directory (and all of its contents) from the local machine to the remote server, use the recursive -r switch, like so:

scp -r /local/directory remoteuser@remotebox:/remote/directory

where /local/directory is the path to the local directory you want copied, and /remote/directory is the remote directory into which you want the directory to be copied.

To copy an entire directory (and all of its contents) from the remote server to the local machine, use the following:

scp -r remoteuser@remotebox:/remote/directory /local/directory

where /remote/directory is the path to the remote directory you want copied, and /local/directory is the local directory into which you want the directory to be copied.

Tuesday, March 30, 2010

PHPMyAdmin Installation on Fedora

Step One
To install PHPMyAdmin using yum, simply issue
# yum -y install phpMyAdmin.noarch
Step Two
PHPMyAdmin Security Access
By default installation, phpmyadmin administration page can only be accessed from localhost via web browser for added security. If you wish to access phpmyadmin page from multiple hosts, modify phpmyadmin conf page as shown below
# vi /etc/httpd/conf.d/phpMyAdmin.conf
and edit the necessary settings. For example, if you require phpmyadmin web page to be accessible from a computer host with an IP address of 123.123.123.123, edit phpMyAdmin.conf to reflect the below similar lines
#order deny,allow
#deny from all
Allow from All
allow from 127.0.0.1
allow from 123.123.123.123


and next add the Allow from All Line
< Directory /usr/share/phpMyAdmin/libraries >
   Order Deny,Allow
   Allow from All
< /Directory>
Save, exit and reload apache web server.
# service httpd restart