How to tweet from command line

First, make sure you have "curl" install on your machine.
if not, install it with
"yum" or "apt-get".










Create a new script with your favorite editor, i like vi
# vi /usr/bin/tweet (as root user)
and copy the next lines to it.

#!/bin/sh

tweet="${@}"
user="USER"
pass="PASSWORD"

if [ $(echo "${tweet}" | wc -c) -gt 140 ]; then
echo "FATAL: The tweet is longer than 140 characters!"
exit 1
fi

curl -k -u ${user}:${pass} -d status="${tweet}" https://twitter.com/statuses/update.xml >/dev/null 2>&1

if [ $? == "0" ]; then
echo "Successful tweet!"
fi

Change the USER to your user name and the PASSWORD to your twitter password.
save and run the command:
# chmod +x /usr/bin/tweet

that's it.

run from your command line
# tweet "Testing tweet sctipt"

and you are twitting.

Read more >>

FileMonitor


Hi,
I was needed for notification when one of my logs is changing.
I didn't find any script or program that doing it, so i write my own program.


File Monitor is the small application which help you monitor after file or directory on you server
and send you notification by mail if there any change on them

Pre install

please verify you have "mutt" installed on your machine
mutt is the mail application that File Monitor use to send emails to you
if not, run "yum install mutt" for Red Hat distribute or "apt-get install mutt" for dubain distribute .

Install
after untar the file:
'tar -zxvf fileMonitor.tar.gz'
go to the untared folder: cd /fileMonitor
run "./install.sh" to complete the installation.

After installation
to start fileMonitor first you have to edit "vi /etc/fileMonitor/fileMonitor.conf" file
you have some parameters to change:
1. which file or directory you want to monitor
2. how many time you want to white between checking
3. what you want to do when your target been changed - check "ls /ect/fileMonitor/scripts"
4. what is your mail who receiver the notification

to start fileMonitor run "/etc/init.d/fileMonitor start"
to stop fileMonitor run "/etc/init.d/fileMonitor stop"
or if you want to restart the aplication run "/etc/init.d/fileMonitor restart"









Save File: filemonitor.tar.gz

Discover Simple, Private Sharing at Drop.io
Read more >>

How to delete files, except the recent one

Hi,
I am using this script to delete logs file from my server.
It search all the files in the certain folder and delete them all except the recent one.
this help me to save disk space on my servers.


#!/bin/sh

DIR=/any/dir/you/want

cd $DIR
lastfile=$(ls -rt | tail -1)
for afile in $(ls | grep -v $lastfile)
do
echo > $afile
rm -rf $afile
done

Enjoy.


Read more >>

Linux commands wallpaper

Discover Simple, Private Sharing at Drop.io
Read more >>

How to ssh without password

On client side, (the machine you want ssh to)
Run the next command.
Use the default settings and an empty passphrase:
# ssh-keygen -t rsa

On the remote machine, (the machine you want ssh from)
Run the next line:
# ssh user@remote test -d \~/.ssh \|\| mkdir \~/.ssh \; cat \>\> \~/.ssh/authorized_keys <~/.ssh/id_rsa.pub
don't forget to change the user@remote to your own one.

OR
you can copy the id_rsa.pub from the clinet machine with :
# ssh-copy-id -i ~/.ssh/id_dsa.pub username@remotebox

END.



Read more >>

How to use ftp in a shell script

If you want to send a file to FTP server for backup or for any other reason,
create new script file with your favorite editor
# vi /usr/bin/ftp_put.sh
and copy the next lines to it

#!/bin/sh
HOST='ftp server'
USER='user name'
PASSWD='password'
FILE='$1'

ftp -n $HOST
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0

change the "ftp server", "user name" and "password" to your needs.
after saving the file, run the next command
# chmod +x /usr/bin/ftp_put.sh

That's it
run this command to send file to your ftp server
# ftp_put.sh /any/file/you/want


Read more >>