Pages

Showing posts with label Shell. Show all posts
Showing posts with label Shell. Show all posts

Monday, January 10, 2011

Print formatted date in shell script

#!/bin/bash
date=`date +%Y/%m/%d_%H:%M`
if tail -1 /home/asd/testlog|grep Error
then
        echo "$date | ups there's an error! restarting smsd ...">>/home/asd/cron.log;
fi

refs:

Tuesday, December 14, 2010

Execute script at certain time

Cronjob used for automating script in certain continues period. For execute once at certain time we can use "at" command.

user@sabily:/etc/cron.weekly$ at -m 10:00 < /home/user/ftp.sh
warning: commands will be executed using /bin/sh
job 1 at Tue Dec 14 10:00:00 2010

Automating sftp with shell script

1. Create public key on local machine

ssh-keygen -t rsa

(just choose the default options. let the passphrase blank, or else you have to enter the passphrase everytime you login. this should generate /home/localuser/.ssh/id_rsa.pub)

2. Login to remote machine 
3. Create file /home/remoteuser/.ssh/authorized_keys (if .ssh folder doesn't exists then create it, and if authorized_keys file is exists then use it)
4. Copy the contents of id_rsa.pub on local machine to authorized_keys file on remote machine
    scp .ssh/id_rea.pub remotehost:.ssh/authorized_keys
5. Run ssh-add on local machine, then you can run: "sftp remoteuser@remotehost" without password