Category Archives: GNU Bash

MySQL – Passwordless login within bash script

As like the previous post about passwordless login within Bash script, this post is about how to connect to MySQL database server using Bash script without MySQL client prompting for login.

Here it is :

mkdir – make a whole set of directory, automatically if it does not exists

When organizing files, we often need to make a whole set of directories in order organize the files properly into directories. Most of the time, we will need to make a bunch of sub directories.

e.g.
“cd /directory” then “mkdir leve1“, then “cd /directory/level1” then “mkdir level2“, then “cd /directory/level1/level2” then “mkdir level3” and etc… In fact, [...]

How to cd back to the previous directory

In Linux & FreeBSD, often we need to cd to a directory then ls to find out the files in that directory. Then only to find out we need to go back to the previous directory and do something else, and we will need to type “cd /very/long/directory/name/and/it/is/just/so/not/cool/to/do/“.

How to print date suitable for file name assignment

In bash script, it is common to name files with date part of it.
e.g.
system-20080808.zip, mysql-20070707.tar.gz, somelog-20090101.tar.bz2 and etc …

Reason to name it in such a ways is easier to clean up the backup later, using bash script. If you have not notice, when listing of the files and sort it by name, it is automatically [...]

How to change the message display upon login

There are some message display after a successful log into the system. e.g. (if your system is running Ubuntu)

“The programs included with the Ubuntu system are free software; the
exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted
by applicable law.

To access official Ubuntu [...]

Linux – how to split / break big files in to smaller chunks

Just did a backup and noticed that the backup tar file is more then 2gb, which fail to copy to a fat32 thumb drive. The mysqldump output text file is more then 5gb and needless to try as it cannot fit into any fat32 formatted drive. Or even regular file that is more then 10mb [...]

bash – how to print or display a new line or tab other then using echo

Printing variables or text within bash script is good for debugging. It can trace which line or variables is having problem. echo is the commonly is used for such debugging purpose. But some times we need it to print tabs, new line & other escape strings in a one liner bash. One way to do [...]

bash – send email with attachment or empty body with mutt

The mutt is not just an email client, it is also very useful in bash script. mutt’s CLI (command line interface) parameter can be called and execute without starting the email client interactively, ideal to run it within bash script to send email. mutt is also able to control from config file, ~/.muttrc, with a [...]

freebsd – convert unix epoch date and time using the date command

Epoch dates are seconds started from 1st January, 1970. It is a common date and time representation, especially in unix and linux world. It provides a way to convert time stamp in a much easier way for programming calculation, an integer. Below are one of the way to convert epoch timestamps to a readable format [...]

bash – read a file line by line instead of word by word

bash script read a file word by word rather then line by line. That means if you have a file with the below contents :

<start of file>

The quick brown fox jumps over the lazy dog

<end of file>

and you read & display it using :
for reading in $(cat /some/directory/some-file);
do
echo $reading;
done

The output would [...]

-->
Improve the web with Nofollow Reciprocity.