Category Archives: Bash

Useful things about Bash scripting

Test OpenSSL ciphers

#!/usr/bin/env bash # OpenSSL requires the port number. SERVER=192.168.1.11:443 DELAY=1 ciphers=$(openssl ciphers ‘ALL:eNULL’ | sed -e ‘s/:/ /g’) echo Obtaining cipher list from $(openssl version). for cipher in ${ciphers[@]} do echo -n Testing $cipher… result=$(echo -n | openssl s_client -cipher “$cipher” -connect $SERVER 2>&1) if [[ “$result” =~ “Cipher is ” ]] ; then echo… Read More »

Copy a file which is generated every day

When you want to copy a file which is generated every day and has a date inserted inside its name, you can use the following bash file: #!/bin/bash dt=`date +%Y%m%d` #dt=`date +%Y%m%d%H%M%S` from_dir=”/home/adrian/1″ to_dir=”/home/adrian/2″ from_file=”$from_dir/myfile”_”$dt”.csv to_file=”$to_dir/myfinalfile.csv”; #echo “cp $from_file $to_file” cp $from_file $to_file #!/bin/bash dt=`date +%Y%m%d` #dt=`date +%Y%m%d%H%M%S` from_dir=”/home/adrian/1″ to_dir=”/home/adrian/2″ from_file=”$from_dir/myfile”_”$dt”.csv to_file=”$to_dir/myfinalfile.csv”; #echo “cp $from_file… Read More »

Bash current folder

Sometimes, if you run some bash scripts from cronjob or with the absolute path you will receive an error like this: Can’t open perl script “backup.cgi”. No such file or directory. To solve this, you must make sure you set bash to read from the directory where it is located: cd $(dirname $0) This will… Read More »

Simple backup in Linux

Sometimes, when you writing code you make a lot of mistakes and you want to go back to a previous version, but you don’t have one. It’s recommended that you always back-up your data. I tried a lot of back-up solutions, but they didn’t satisfy what I need. I need to make a backup to… Read More »