2011 November
November 30, 2011
bash script useful tips
At Learnosity I’ve spent last 2 days scripting virtual server deployment on Amazon cloud. For my reference, these are some useful commands I had to use to get the job done.
1. Hash “Hello World” string using SHA256 algorithmecho -n "Hello World" | shasum -a 256
You can also hash a file
shasum -a 256 myfile.ext
2. Display server IP address by stripping out all other network information, including the local 127.0.0.1 IP
ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'
3. Read out first 64 characters from a long string
${mystring:0:64}4. While loop with 10 iterations
i=0; while [ $i -lt 10 ] do echo $i i=$[$i+1] done
5. Replace contents of a file. For example search for string1, replace with string2 in myfile.txt
sed -e "s/string1/string2/g" myfile.txt > myfile.txt_temp mv myfile.txt_temp myfile.txt
6. Display number of CPU processors on Linux
The command simply pulls out all instances of the word ‘processor’ from /proc/cpuinfo and returns the word count of it.cat /proc/cpuinfo | grep processor | wc -l
Marko
TopNovember 24, 2011
apr_sockaddr_info_get() failed for mydomain.com
I recently changed my ISP from Optus to TPG and when I tried to start my local apache instance and I got this error
httpd: apr_sockaddr_info_get() failed for 192-168-1-107.tpgi.com.au httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
That gave me a hint that my local hostname had changed. I reset it back to what it was originally like this:
sudo hostname myoldhostname.local
Restarted apache and it was smooth sailing again.
Marko
Top