Categories
Hosting Tips & Deals Linux Server Administration Tips PHP Tips & Tutorials

Cron jobs (Crontab jobs) tricks and tips on DreamHost

Crontab is a utility tool on Unix-like OS that enables you to make a program daemon scheduled to run at a specified interval. For example, to fetch news feed and import them into your own database every hour on the hour or to send pre-written newsletters at a given time everyday.

With DreamHost you can easily add Crontab jobs at their proprietary web panel, but there are 2 tricks.

With PHP, you can specify the version to run the script, PHP4 or PHP5. DreamHost has both popular php versions installed at different locations:

/*PHP4: */
/usr/local/bin/php
/*PHP5: */
/usr/local/php5/bin/php

With any PHP script, you can always achieve the same results with lynx -dump command that accesses and loads the script as any other browsers would do, thus making the server run the script.

Also it’s required to add this line:

#!/usr/local/bin/php -q

at the top before <?php declaration if you are configuring crontab in command line mode rather than adding it from the web panel of DreamHost.

Categories
Hosting Tips & Deals Linux Server Administration Tips

Colorful Linux Bash Console by .alias and .bash_profile

At Dreamhost, we are all granted unlimited number of accounts for SSH access to the servers. The default console setting is a monochromatic one just like that in the old DOS style that it sores the eyes to look through the lines for something. Read their wiki the other day and found it’s possible to reconfigure the color scheme to ease of console operations.

.alias and .bash_profile are the 2 basic console configuration files located at your home directory, hidden by default, and you have to use ‘ls -a’ to get them in sight. Download them via FTP and add a line:

alias ls 'ls --color=auto'

at the end of the file .alias, and add a line:

alias lsl='ls --color'

to the end of .bash_profile. Upload and replace the old ones on your server with them. Now you are blessed with a colorful console with the command ‘lsl -o‘, just like the one I have:

image

Enjoy!

Categories
Hosting Tips & Deals Linux Server Administration Tips

Essential SSH – 19 Linux SSH Commands You Simply Cannot Live Without

More and more web hosting providers are offering SSH(Secure Shell) access to their customers now, if you are one of them, put this advantage to good use will make your online life a lot easier. Don’t worry, we are just going to deal with just a few more than 15 shell commands, pretty much those used most frequently, with the most favored switch options by most people.

We have assumed that you are normally computer- and internet- literate, at least aware of directories and files that facilitate the organization of data on computers, knowing what it is like to travel within a file system tree structure.

First off, you are to log in to the host with your SSH privilege by means of a SSH client, like Putty. Download and launch it on your local machine. The interface should look like this:

SSH client

Enter the host name or IP address supplied by your hosting provider in the Host Name box and click Open.

Supply your SSH account username and password so as to be logged in. Once acknowledged by the remote system, it is ready to accept your commands, and you should be in your home directory which can be referred to as ‘~’ or ‘/home/username’ (username here is a placeholder for your own SSH username) in SSH commands. Now let’s see in detail what you can do in this tiny terminal window.

  1. ls -o : List files and directories in the current directory. 
    ls -ao : List files and directories in the current directory, including hidden ones.
  2. cd [dir-path] : Change to, or change current directory to the directory indicated by [dir-path].
    cd ~ : Change to your home directory, which in most cases would be /home/yourusername.
    cd .. : Change to the parent directory of the current one.
    cd – : Change to the last directory you are in.
  3. pwd : Show the full path to the current directory.
  4. mkdir [dir-path] : Create an empty directory in the specified directory indicated by [dir-path].
  5. rmdir [dir-path] : Delete an empty directory in the specified directory indicated by [dir-path].
  6. rm [file-path] : Delete a file indicated by [file-path]. 
    rm -f [file-path] : Forcibly delete a file indicated by [file-path], that is, without having to confirm before deletion.
    rm -r [dir-path] : Delete a directory indicated by [dir-path] and everything underneath it.
    rm -rf [dir-path] : Delete a directory indicated by [dir-path] and everything underneath it, without having to confirm before deletion.
  7. mv [file-path]/[dir-path] [dir-path] : Move a file or directory indicated by [file-path] or [dir-path] to the directory indicated by the latter [dir-path]. 
    mv [file-path] [file-path] : Rename the file indicated by the first [file-path] to another indicated by [file-path]. Or. Move the first file to a different location and rename it as specified in the second [file-path].
  8. cp [file-path] [dir-path] : Copy the file indicated by [file-path] to the directory indicated by [dir-path]. 
    cp [file-path] [file-path] : Duplicate the same file indicated by [file-path] with another name indicated by the second [file-path]. Or. Copy the first file to another location and rename it as specified in the second [file-path].
    cp -r [dir-path] [dir-path] : Copy a whole directory including everything underneath it indicated by the first [dir-path] to another directory indicated by the second [dir-path].
  9. tar -zxf [file-path] : Extract all things in an archive extensioned with .tar.gz indicated by [file-path] to the current directory. 
    tar -xf [file-path] : Extract all things in an archive extensioned with .tar indicated by [file-path] to the current directory.
    tar -cf [file-path] ([file-path]/[dir-path], … ) : Create an archive indicated by the first [file-path] of the files indicated by [file-path]s or/and directories indicated by [dir-path]s.
  10. gunzip [file-path] : Decompress a zipped file extensioned with .gz to the current directory.
    unzip [file-path] : Decompress a zipped file extensioned with .zip to the current directory.
  11. chmod [xxx] [file-path]/[dir-path] : Change the privileges of a given file or directory indicated respectively by [file-path] and [dir-path] to xxx. 
    chmod -r [xxx] [dir-path] : Change the privileges of a given directory indicated by [dir-path] to xxx.
  12. more [file-path] : Display the content of the given file indicated by [file-path], one screen at a time.
  13. ln -s [file-path] [file-path] : Create a symbol link for the first file, so that everything you do to the symbol link, a.k.a the second fake file, is reflected to the real file, except for when you delete the symbol link, the real file remains intact.
  14. touch [file-path] : Create an empty file indicated by [file-path].
  15. du -sh : Show disk usage of the current directory. 
    du -sh * : Show disk usage of the current directory plus the statistics of all the files and directories underneath it.
  16. grep [text] [file-path] : Search the file indicated by [file-path] with the text in [text].
  17. mysqldump -h [hostname] -u [username] -p [password] [database] > [databasefile.sql] : Dump or backup the selected database on the selected host privileged by selected user identified by corresponding password to a SQL file. 
    mysql -h [hostname] -u [username] -p [password] [database] < [databasefile.sql] : Restore the data in a SQL file to the selected database on the selected host privileged by selected user identified by corresponding password.
  18. clear : Clear the screen so that you feel neat.
  19. exit : Terminate the SSH dialogue and close the Putty window.

Note: When something is specified in brackets, such as [file-path] or [dir-path], it is used to indicate that you must input your desired information here, which, in this case, are the path to a file or a path to a directory respectively. NO brackets in your command.