Category Archives: Shell script

Some useful linux/unix command and automation with shell scripting

WordPress sites backup shell script

WordPress sites backup shell script #! /bin/bash ## backup script for the wordpress site ## taking complete backup of website folder, database & apache configuration files ## itquery(at)gmail.com TIMESTAMP=$(date +”%F”) IPA=`hostname -I| awk ‘{print ($1)}’` BACKUP_DIR=”/backup/BKP_$IPA/$TIMESTAMP” #### Website folder path … Continue reading

Posted in Database, Shell script | Leave a comment

Web server securing guide

1   OS Hardening 1.1          Kernel hardening Update kernel parameter on /etc/sysctl.conf # Turn on exec shield kernel.exec-shield=1 kernel.randomize_va_space=1 # Enable IP spoofing protection net.ipv4.conf.all.rp_filter=1 # Disable IP source routing net.ipv4.conf.all.accept_source_route=0 # Ignoring broadcasts request net.ipv4.icmp_echo_ignore_broadcasts=1 net.ipv4.icmp_ignore_bogus_error_messages=1 # Make sure spoofed … Continue reading

Posted in Apache, Shell script, Unix/Linux | Leave a comment

awk one liners

### In order to join 2 lines seprated with new line “^M” character $awk ‘/^M$/ {print;next;} {printf(“%s”,$0);}’ FileName.txt

Posted in Shell script, Unix/Linux | Leave a comment

SQL query output in CSV format (MySQL)

SQL query output in CSV format (MySQL). You can have your SQL Query saved as a file “QUERY.sql” SELECT FIELD1, FIELD2, FIELD3 … from TABLEName WHERE COLUMNName = ‘$VALUE’ INTO OUTFILE ‘/tmp/DataFile_output.csv’ FIELDS TERMINATED BY ‘,’ ENCLOSED BY ‘”‘ LINES … Continue reading

Posted in Database, Shell script | Tagged | Leave a comment

FTP Script to transfer only changed files

FTP Script to transfer only changed files using FTP protocol Save below script as “Ftpenv.sh” #!/bin/sh ############################################################ # File:         Ftpenv.sh # Description:  Setup Environment Variables for FTP task by itquery ############################################################ REMOTE_FTP_SERVER=192.168.0.1   # Server where to put the Incremental Load … Continue reading

Posted in Shell script, Unix/Linux | Tagged , | Leave a comment

SED on-liners

Stream Editor or SED on-liners : ====================== ##To print line first 10 from a file $sed -q10 filename.txt ## Find and replace pattern text $sed ‘s/find_text/replace_text/g’ file.txt

Posted in Shell script, Unix/Linux | Tagged | Leave a comment

Script to find log file larger then 1GB /1024MB and delete it

Script to find log file larger then 1GB and delete it #!/bin/sh #find / -name ‘*.log’ -size +1024M -print |xargs /bin/rm find / -name ‘*.log’ -size +1G -print |xargs /bin/rm This  will try to find files from “/” root directory … Continue reading

Posted in Shell script, Unix/Linux | Leave a comment