Sometimes it is necessary, for example, to delete all IPTables rules and to add only the necessary, so for convenience, you can specify them in the script, and then execute it.
Continue reading “IPTables quick setup script”Category Archives: Scripts
ClamAV script for automatic scanning and email notifications
I will give an example of a script for scanning and email notifications when infected files are detected.
Continue reading “ClamAV script for automatic scanning and email notifications”Simple Watchdog script
I will give an example of a simple script for restarting services if they are not running and sending a notification by email:
Continue reading “Simple Watchdog script”Backup script example
I will write below a simple example of backing up mysql databases using mysqldump.
Continue reading “Backup script example”The script against DDOS attacks
I will give an example of a simple script against DDOS attacks for NAT servers.
The script is executed when the total number of “conntrack” connections is more than 500000, it saves to the text file the IP address which has the most “conntrack” connections, who has more than 10,000 – adds to the ipset list.
File Transfer Script over SFTP in Windows
I will give an example of a file transfer script via SFTP in Windows.
Continue reading “File Transfer Script over SFTP in Windows”PPS Viewer Script (Packets Per Second)
The script every second displays the number of incoming and outgoing packets per second on the specified network interface.
Place the contents of the script into a file, for example, pps.sh and execute by specifying the name of the network interface (you can stop the execution of the script with CTRL+C):
Script to send SMS via Goip4 gateway for ABillS
I will give an example of a PHP script to which I send SMS messages through the GoIP4 gateway.
First, we choose tariffs with only monthly charges:
Continue reading “Script to send SMS via Goip4 gateway for ABillS”How to pull data from one column of a mysql table
To see data from one column, it is enough to execute the SQL query (where “abcd” is the name of the column in the table):
SELECT abcd FROM table;
To export to a file, just run the command in Linux:
mysql -u root -e "SELECT abcd FROM database;" -s -N > file.txt
Here is an example of exporting email addresses from a mysql table to an http page using PHP.
The thought immediately came to this plan (create a php file and open it through the browser):
<?php // Connecting to mysql server mysql_connect("localhost", "USER", "PASSWORD") or die (mysql_error ()); // Choosing a database mysql_select_db("users") or die(mysql_error()); // SQL query $rows = "SELECT * FROM account"; // Run this SQL query $d = mysql_query($rows); // Each row becomes an array ($row) using the mysql_fetch_array while($row = mysql_fetch_array($d)) { // Display the values of the email column echo $row['email'] . "<br />"; } // Close the connection to the database mysql_close(); ?>
Back Up Cisco Catalyst 6500 Configuration
For the test, I sketched a Cisco Catalyst 6509-E automatic backup configuration script.
Actually the script itself:
#!/bin/bash # Backup CISCO config ( sleep 5 echo "user" sleep 4 echo "password" sleep 4 echo "copy running-config tftp:" sleep 2 echo "192.168.1.4" sleep 2 echo "cisco.cfg" sleep 6 echo "exit" ) | telnet 192.168.1.5 mv /srv/tftp/cisco.cfg /backups/devices/cisco/`date +%Y-%m-%d`_cisco.cfg find /backups/devices/cisco/ -type f -mtime +30 -exec rm {} \;
Add the contents of the script, for example, to the backup_cisco.sh file and add it to cron, adding the following line to the /etc/crontab file:
0 2 * * * root /backups/scripts/backup_cisco.sh > /dev/null 2>&1
The file can be opened for example in the text editor nano (Ctrl+X to exit, y/n to save or cancel changes):
sudo nano /etc/crontab
The script connects via telnet to 192.168.1.5 and copies the configuration to the tftp server 192.168.1.4, then the file is moved to a convenient directory for storage.
The last line in the script deletes files older than 30 days.
How to start the tftp server, see my articles: Installing and Configuring a TFTP Server in Ubuntu or Starting a TFTP server in Windows.
See also: Using and configuring CRON.