Posts

Showing posts with the label Linux Commands

How to send email using mail command in linux

Image
in my post, i'm use mail command to send message email. mail -s "Subject title huuphan.com" -S [email protected] <<EOF ---------------------------------------- The content email Hello phan van huu My site: huuphan.com ----------------------------------------- EOF The script sending 100 email from command. #!/bin/sh i=1 for (( i = 1 ; i <= 100 ; i++ )); do  echo "Test Mail $i, Send from mail.huuphan.com" | mailx -v -r "[email protected]" -s "Test Mail $i" -a "/tmp/quotausage" -S smtp="mail.huuphan.com:25" -S smtp-auth=login -S smtp-auth-user="[email protected]" -S smtp-auth-password="123456789" -S ssl-verify=ignore -S nss-config-dir=/etc/ssl/certs [email protected],[email protected] done

xdotool − command−line X11 automation tool

Image
To install xdotool on ubuntu sudo apt-get update sudo apt-get install xdotool To install xdotool on fedora sudo yum install xdotool To display the current coordinates of the mouse cusrsor on linux #while true; do clear; xdotool getmouselocation; sleep 0.1; done The simple script for xdotool #!/bin/bash xdotool mousemove 343 755 click 1 sleep 2 while true do     xdotool mousemove 392 44 click 1     xdotool key "Return"     sleep 3     xdotool key Page_Up     sleep 3     xdotool mousemove 277 580 click 1     sleep 3     xdotool key Page_Down     sleep 3     xdotool mousemove 718 152 click 1     sleep 3     xdotool mousemove 46 482 click 1     sleep 3     xdotool mousemove 383 15 click 1     sleep 3 done Man xdotool http://man.cx/xdotool

How to running cron job every 5 minutes,seconds,hours,days

Image
How to running cron job every 5 minutes,seconds,hours,days. How to running a script a specific interval using cronjob in linux.  To execute a cronjob every 5 minutes */5 * * * * /home/huupv/script.sh To execute a cronjob every 5 hours 0 */5 * * * /home/huupv/script.sh How to running a job every 5 seconds $ cat every-5-seconds.sh #!/bin/bash while true do  /home/huupv/script.sh  sleep 5 done $ nohup ./every-5-seconds.sh & To execute a cronjob every 5th weekday 0 0 * * 5 /home/huupv/script.sh or 0 0 * * Fri /home/huupv/script.sh 0=Sun 1=Mon 2=Tue 3=Wed 4=Thu 5=Fri 6=Sat

Bash Scripting Made Simple: Practical Examples

Bash Scripting Made Simple: Explore practical examples to streamline your workflow and enhance your bash scripting skills effortlessly. List all IP addresses connected to Server Discovering all IP addresses connected to the server is essential for network monitoring and security. Utilize tools like netstat or ss commands to obtain this information efficiently. #!/bin/bash while true; do echo "CTRL+C TO BREAK" netstat -tnu | grep :22 | awk '{print $5}' | cut -f1 -d : | sort | uniq -c | sort -nr | head -n 8 sleep 15 clear done ########################################################################################### # site: huuphan.com # author: phan van huu # List all IP addresses connected to Server # For example: list ip address connected to server via ssh port 22 # awk '{print $5}' | cut -f1 -d : | sort | uniq -c | sort -nr | head -n 8 # awk '{print $5}': the display 5th field only # sort | uniq -c | sort -nr: Sort the list, group it

The usefull linux commands

Welcome to our guide on mastering essential command-line operations and system management tasks! In this blog post, we'll explore practical tips and tricks to streamline your workflow and boost productivity. Whether you're a beginner or an experienced user, these techniques will help you navigate the command line with ease. Join us as we dive into managing log files, executing commands efficiently, and optimizing your system administration skills for success. How to find and delete logs file MORE THAN 30 DAYS OLD # find /path/to/log/ -type f -name \*.log\* -mtime +30 -exec rm {} \; > /dev/null 2>&1 How to find and delete logs file   LESS THAN 30 DAYS OLD # find /path/to/log/ -type f -name \*.log\* -mtime -30 -exec rm {} \; > /dev/null 2>&1 How to one-liner that allows to create a directory and move into it at the same time. # mkdir test-dir && cd $_ How to display size of folder. #du -csbh /path/to/folder How to display output as a table # cat /etc/p

iptables examples

How to allow or denied on iptables firewall on centos. To configure iptables static file on centos.  You may reading link as below: Iptables how to How to reset password on centos 7 Bash script example *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT #### Mail port ### -A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 389 -j ACCEPT -s 10.10.9.0/24 -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT -A INPUT -m state --state NEW -m tcp -p tcp --dport 465 -j ACCEPT -A INPUT -m state --state NEW -