Programming and writing about it.

echo $RANDOM

Category: Shell Scripts

Automating your FTP session using expect

Shamelessly derived from a code on the Wikipedia entry for Expect, here is how you would automate a FTP session:

# Open an ftp session to a remote server, logs in using your credentials and retrieves the current
# directory listing from there

# Amit k. Saha

# This is how you set variables in 'expect'

set remote_server your-ftp-server
set my_user_id your-user-ide
set my_password your-pass

spawn ftp $remote_server
expect "username:"

# Send the username, and then wait for a password prompt.
send "$my_user_id\r"
expect "password:"
# Send the password, and then wait for an ftp prompt.
send "$my_password\r"

expect "ftp>"

# list all the files
send "ls \r"

expect "ftp>"

# Exit the ftp session, and wait for a special end-of-file character.
send "bye\r"
expect eof


Shell script to rotate a bunch of Images

# Uses the 'convert' utility to rotate a bunch of images via some specified angle in
# clockwise
# By Amit K.Saha

# Angle is to be supplied as a command line parameter
#./ 90

for i in *.png
convert -rotate $1 $i $i

Shell Scipt to convert a bunch of images using ‘convert’

convert is a command line tool available with ImageMagick which can be used to convert between image formats. This shell script uses it to convert a bunch of images from ‘.ps’ to ‘.png’. Follow embedded instructions to customize it to your needs.


# Uses the 'convert' utility to convert a bunch of images from one
#format to another
# the script should reside in the same directory as the images
# You need to have 'ImageMagick' installed

# By Amit K.Saha
# Help taken from

#to convert to/from different formats
# change 'ext' to reflect the format you want to convert "from"
# Chnage target to the format you want to convert to


for i in *.ps
base=$(basename $i $ext) #to extract only the filename and NOT the extension
convert $i $base.$target