send mail using telnet from script

If you have no other option but to use telnet with authentication to send mail 🙂

 ( echo "ehlo"
sleep 1
auth login
sleep 1
$(echo username |base64)
sleep 1
$(echo password |base64)
sleep 1
mail from: from-address
sleep 1
rcpt to: recepient
sleep 1
data
sleep 1
subject: test 
test mail
. 

exit ) |telnet server port

change the output format for time command

If you are doing some scripting and using ‘time’ command, then you know sometimes it becomes difficult to capture the output as the output would be something like this:

: amit ; time ls

real    0m0.002s
user    0m0.000s
sys 0m0.001s

So, it is better to change that format. Here is simple example:

1
 
TIMEFORMAT=’real %3R user %3U sys %3S pcpu %P’ time ls
amit ;  TIMEFORMAT=’real %3R user %3U sys %3S pcpu %P’ time ls
0.00user 0.00system 0:00.00elapsed 0%CPU (0text+0data 2432max)
0inputs+0outputs (0major+109minor)pagefaults 0swaps
amit ; TIMEFORMAT=’real %3R user %3U sys %3S’
amit ; time ls
real 0.001 user 0.001 sys 0.000
amit ;
amit ; TIMEFORMAT=’TIMEOUTPUT = real %3R user %3U sys %3S’
amit ; time ls
TIMEOUTPUT = real 0.001 user 0.001 sys 0.000
amit ;

bash refer parameters from the current command

In bash you can use

!#

to refer to any parameter from the current command, example:

mv ak amit.!#:1.txt
ls amit.ak.txt