Archive for category Linux/Unix
Returning linux timestamp
Posted by Maz in Linux/Unix, Shell Scripting on January 30, 2014
To return linux timestamp use the following:
Date and time now in timestamp format:
date "+%s"
A specific date and time in timestamp format:
date -d "<time>" "+%s"
e.g. date <del>d "2014</del>01-30 15:00:00" "+%s"
</time>
Date and time now in timestamp format and nano seconds:
date "+%s%N"
Date and time now in timestamp format and milli seconds:
date “+%s%N” | cut -
b1-13
or
echo $(($(date “+%s%N”)/1000000))
To return a specific date and time in timestamp with nano or milli seconds then simply add -d parameter similar to the previous example.
How to convert Scientific Notation number to Decimal using bash?
Posted by Maz in Linux/Unix, Shell Scripting on April 16, 2013
Turns out this is pretty easy to do using awk and printf in bash!
Lets say you have a scientific value of “2.1061863333e+03” and you wish to convert it to decimal. You can do something like below:
>> echo "2.1061863333e+03" | awk {' printf "%12.2fn",$1 '} 2106.19
- Obviously you can do the same if you have series of values in a file using cat.
- I found this specially useful when obtaining values from RRDs.
Need to modify linux filesystem when mounted in read-only?
Posted by Maz in Linux/Unix on June 30, 2011
In cases where you’re at the Repair Filesystem prompt and need to modify one or more files to fix what is broken then you can mount the root in read-write mode to avoid needing the rescue disk. Otherwise the disk is mounted in read-only mode and you’re unable to modify any files.
The following command will mount the root in read-write mode:
mount -w -o remount /
SELinux basic commands
Posted by Maz in Linux/Unix on June 7, 2011
Get a list of all rules currently applied:
getsebool -a
Set a SELinux rule:
setsebool -P <rule_name>=X where X is 0 for OFF and 1 for ON</rule_name>
VSFTPD on CentOS – Unable to list files or directories
Posted by Maz in Linux/Unix, vsFTP on June 7, 2011
Details:
- Running VSFTPD on CentOS
- The FTP port is opened through IPTables
- Authenticating using the user credentials works
- XferLog doesn’t provide any specific details
Solution
- Checkout /var/log/messages for any hints as to the problem
- SELinux is blocking the FTP daemon from listing the home directory. Use
setsebool -P ftp_home_dir=1
to relax the rule in SELinux
MySQL – Backup Script
Posted by Maz in Databases, Linux/Unix, MySQL on March 15, 2011
#!/bin/bash
- Shell script to backup MySql database
- To backup Nysql databases file to /backup dir and later pick up by your
- script. You can skip few databases from backup too.
- For more info please see (Installation info):
- http://www.cyberciti.biz/nixcraft/vivek/blogger/2005/01/mysql-backup-script.html
- Last updated: Aug - 2005
- --------------------------------------------------------------------
- This is a free shell script under GNU GPL version 2.0 or above
- Copyright (C) 2004, 2005 nixCraft project
- Feedback/comment/suggestions : http://cyberciti.biz/fb/
- -------------------------------------------------------------------------
- This script is part of nixCraft shell script collection (NSSC)
- Visit http://bash.cyberciti.biz/ for more information.
- -------------------------------------------------------------------------
MyUSER="SET-MYSQL-USER-NAME" # USERNAME
MyPASS="SET-PASSWORD" # PASSWORD
MyHOST="localhost" # Hostname
- Linux bin paths, change this if it can not be autodetected via which command
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
CHOWN="$(which chown)"
CHMOD="$(which chmod)"
GZIP="$(which gzip)"
- Backup Dest directory, change this if you have someother location
DEST="/backup"
- Main directory where backup will be stored
MBD="$DEST/mysql"
- Get hostname
HOST="$(hostname)"
- Get data in dd-mm-yyyy format
NOW="$(date +"%d-%m-%Y")"
- File to store current backup file
FILE="" - Store list of databases
DBS=""
- DO NOT BACKUP these databases
IGGY="test"
[ ! -d $MBD ] && mkdir -p $MBD || :
- Only root can access it!
$CHOWN 0.0 -R $DEST
$CHMOD 0600 $DEST
- Get all database list first
DBS="$($MYSQL -u $MyUSER -h $MyHOST -p$MyPASS -Bse 'show databases')"
for db in $DBS
do
for i in $IGGY
do [ "$db" "$i" ] && skipdb=1 || :
done fi if [ "$skipdb" “-1” ] ; then
FILE=”$MBD/$db.$HOST.$NOW.gz”
- do all inone job in pipe,
- connect to mysql using mysqldump for select mysql database
- and pipe it out to gz file in backup dir
done
Cron Job:
@daily /path/to/yourmysql.sh
iSCSI discovery fails with FreeNAS
Error Messages:
Windows Server 2008:
Connection Failed
The iSCSI name specified contains invalid characters or is too long.
Solution:
This issue drove me crazy. I checked the firewall, connectivity, event viewer but didn’t come across anything that would indicate the real problem. I finally checked the log for FreeNAS and didn’t see anything that would indicate what is the problem. After a reboot on the Windows machine and trying again the following warning message showed up in the log which shed light on the issue:
FreeNAS Log:
istgt[2330]: istgt_lu.c:1232:istgt_lu_add_unit: ***WARNING*** TargetName iqn.2007-09.jp.ne.peach.istgt:SQL_Log contains an invalid character.
As you can see in the error message I had named the target as SQL_Log and it looks like the underscore caused the problem! Removed the underscore and fixed the issue..
ProFTPD: getting terminated once a week
Posted by Maz in Linux/Unix on September 14, 2010
Once a week on Monday morning when I would come to work the ProFTPD process on one of my linux boxes (Fedora) had terminated and I had to restart the service to get it going. After checking the logs I found that it happened exactly 2AM on Monday morning every week. The following was the error I was getting in the logs:
received SIGHUP -- master server reparsing configuration file
After a bit of research I found that the process was included in the /etc/logrotate.d directory and what was happening was that the logrotate was attempting to rename the log file, compress it and create a new one however that seemed to crash the ProFTPD server. Removed the proftpd entry from the directory and resolved the issue.