Linux Microsoft VMware
Showing posts with label Scripts. Show all posts
Showing posts with label Scripts. Show all posts

Wednesday, September 5, 2012

Shell Script To Encrypt Any Given Text File


In cryptography, encryption is the process of transforming information (referred to as plaintext) using an algorithm (called cipher) to make it unreadable to anyone except those possessing special knowledge, usually referred to as a key.
Mcrypt is a simple crypting program, a replacement for the old unix crypt. When encrypting or decrypting a file, a new file is created with the extension .nc and mode 0600. The new file keeps the modification date of the original. The original file may be deleted by specifying the -u parameter. If no files are specified, the standard input is encrypted to the standard output.

Shell Script List All Top IP Address Accessing Apache Web Server


********************************
#!/bin/bash
# Shell Script To List All Top Hitting IP Address to your webserver.
# This may be useful to catch spammers and scrappers.

# where to store final report?
DEST=/var/www/reports/ips

Basic of Shell Script


What Is a Shell?


Ø       The shell is a user program or it is an environment provided for user interaction.
Ø       It is a command language interpreter that executes commands read from the standard input device such as keyboard or from a file.
Ø       The shell gets started when you log in or open a console (terminal).
Ø       Quick and dirty way to execute utilities.
Ø       The shell is not part of system kernel, but uses the system kernel to execute programs, create files etc.
Ø       Several shells are available for Linux including:
Ø       BASH ( Bourne-Again SHell ) - Most common shell in Linux. It's Open Source.
Ø       CSH (C SHell) - The C shell's syntax and usage are very similar to the C programming language.
Ø       KSH (Korn SHell) - Created by David Korn at AT & T Bell Labs. The Korn Shell also was the base for the POSIX Shell standard specifications.
Ø       TCSH - It is an enhanced but completely compatible version of the Berkeley UNIX C shell (CSH).
Please note that each shell does the same job, but each understands different command syntax and provides different built-in functions. Under MS-DOS, the shell name is COMMAND.COM which is also used for the same purpose, but it is by far not as powerful as our Linux Shells are!

Wednesday, August 8, 2012

Automatic Mysql DB Backup Scripts

 Automatic Mysql DB Backup Scripts With Compress and auto Deletion of Old Archive Files

:: UPDATE 3.30.2012  Added error logging to help trouble shoot databases backup errors.   --log-error="c:\MySQLBackups\backupfiles\dumperrors.txt"

::If the time is less than two digits insert a zero so there is no space to break the filename

set year=%DATE:~10,4%
set day=%DATE:~7,2%
set mnt=%DATE:~4,2%
set hr=%TIME:~0,2%
set min=%TIME:~3,2%

IF %day% LSS 10 SET day=0%day:~1,1%
IF %mnt% LSS 10 SET mnt=0%mnt:~1,1%
IF %hr% LSS 10 SET hr=0%hr:~1,1%
IF %min% LSS 10 SET min=0%min:~1,1%

set backupdate=%year%-%day%-%mnt%-%hr%-%min%



:: MySQl DB user
set dbuser=aaa

:: MySQl DB users password
set dbpass=yyy

:: Switch to the MySQL data directory and collect the folder names
pushd "C:\Documents and Settings\All Users\Application Data\MySQL\MySQL Server 5.1\data"

:: Loop through the folders and use the fnames for the sql filenames, collects all databases automatically this way

echo "hello"

echo "Pass each name to mysqldump.exe and output an individual .sql file for each"

FOR /D %%F IN (*) DO (
"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump.exe" --user=%dbuser% --password=%dbpass% --databases --log-error="c:\MySQLBackups\backupfiles\dumperrors.txt" %%F > "c:\MySQLBackups\backupfiles\%%F.%backupdate%.sql"
)

echo "Zipping all files ending in .sql in the folder"

"c:\MySQLBackups\zip\7zG.exe" a -tzip "c:\MySQLBackups\backupfiles\FullBackup.%backupdate%.zip" "c:\MySQLBackups\backupfiles\*.sql"

echo "Deleting all the files ending in .sql only"

del "c:\MySQLBackups\backupfiles\*.sql"

echo "Deleting zip files older than 30 days now"
Forfiles -p c:\MySQLBackups\backupfiles\ -s -m *.* -d -30 -c "cmd /c del /q @path"
echo "All done, pretty slick eh"
Powered by Blogger.