Sunday, October 25, 2009

Send email from UNIX | Perl script

This will show you how to send an email from unix server using a perl script.

open (MsgFILE, "> $msgFile");
print MsgFILE "\n I am sending an email to all of you \n";

close(MsgFILE);
print "\n sending mail....\n" if $debug;

open (MAIL,"|(cat $msgFile ; uuencode $file $to_file_name) | mailx -r $from -c $MailCc -s \"$Subject\" $to") or die "Cannot open sendmail: $!";

close MAIL;

To set up SSH Keys - UNIX

The process of creating SSH - Version 2 keys in the destination server is given below.

Login to source server using the your user id
scp id_dsa.pub user@destination_server:./id_dsa.pub


Login to the destination server using the user name and password
cd .ssh
touch authorized_keys2
chmod 600 authorized_keys2
cat ../id_dsa.pub >> authorized_keys2
rm ../id_dsa.pub

Logout from the destination server and try to login from source server again using the following command,

ssh -2 -v user@destination_server
Or
ssh destination_server

vi editor is throwing error '5826'

This happens because of several reasons. If the same file is opened under the same user in a different system, this problem can occur. Never mind, never worry about this problem. You just need to update the env variable of the user.

export EDITOR=vi

Change Password in UNIX

To change password in UNIX ,

1. If you already know the old password,
then run the command 'passwd'.

2. If you dont remember, better you ask sysadm :)