crontab -e
then, helped by crontab.guru, add a new line like:
0 14 * * * echo "hello" > ~/Desktop/output_cron.log
every day at 14:00, output 'hello' in the file '~/Desktop/output_cron.log'
To list all active CRONs:
crontab -l
To delete all active CRONs:
crontab -r
To create a system-wide CRON, append the CRON:
sudo nano /etc/crontab
ls /etc/init.d/
systemctl list-unit-files --type=service
# or sudo service --status-all
ps aux
kill -9 <PID>
xkill
then click the window to kill
# create asymetric public/private keys
ssh-keygen -t rsa -C "[email protected]"
# send keys to distant server
ssh-copy-id -i ~/.ssh/my_key_rsa.pub -p 22 [email protected]
sudo apt-get install net-tools
sudo netstat -ntapul
Caution: iptables rules ORDER MATTERS. We first need to explicitly list allowed ports BEFORE denying all others.
# List all firewall rules
sudo iptables -L
# !!!!! DANGEROUS !!!!!
# Flush/Delete all firewall rules
sudo iptables -F
# Allow ports 22, 80 and 443
sudo iptables -I INPUT -p tcp --dport 22 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -I INPUT -p tcp --dport 443 -j ACCEPT
# Deny everything else
sudo iptables -P INPUT DROP
after reboot, all iptables config gets wiped out. To make them persistent:
Create a file to store iptables rules, make it executable:
echo "#!/bin/sh" > /etc/network/if-up.d/iptables
echo "iptables-restore < /etc/firewall.conf" >> /etc/network/if-up.d/iptables
chmod +x /etc/network/if-up.d/iptables
tweak your iptables rules to your liking or edit /etc/firewall.conf
. Then, when everything is fine, save them:
iptables-save > /etc/firewall.conf
the bash script we saved to /etc/network/if-up.d/iptables
will reload iptables rules defined in /etc/firewall.conf
at startup.
fail2ban will "put in jail" IP that attempts to connect to your machine after some unsuccessful attempts.
sudo apt-get install fail2ban
# copy example config file
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
# edit configurations
sudo nano /etc/fail2ban/jail.local
# restart fail2ban
sudo service fail2ban restart
du -hac .
df -h
sudo apt-get autoremove <program>
free -h
Useful when computer gets slow because RAM exceeded usage. Swap being really slow, disabling swap will put data back to RAM.
# Disable
sudo swapoff -a
# Enable
sudo swapon -a
myexecutable & > mylog.log
#!/bin/bash
crawl () {
echo page$1 &&
page=`wget -U 'Mozilla/5.0 (X11; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0' \
https://www.leboncoin.fr/_immobilier_/offres/ile_de_france/p-$1 -qO-` &&
if [[ $page =~ (window.__REDIAL_PROPS__.=.)(.*])(.</script>) ]]; then
echo "${BASH_REMATCH[2]}";
else
echo "no match found";
fi > page$1.json
}
for i in {1..100}
do
crawl $i &
done
wait
Vim is quite derouting at first if you don't know what to do...
# open/create file `myfile.txt`
vi myfile.txt
Navigate the document using keyboard arrows. Then to edit the document: PRESS i
on your keyboard.
Make changes... then to close the document: press ESC
on your keyboard, then type :wq
and press ENTER
:wq
: write changes + quit
:!q
: force quit and loose changes