Pages

Showing posts with label shell script. Show all posts
Showing posts with label shell script. Show all posts

Saturday, August 24, 2013

Shell script to assign each column value as a variable

Consider a txt file with two columns and many rows.

You may want to write a script which will take each column values in each row as variables

Then you can use the following script.



#!/bin/bash
cat text.txt | while read line;
do
var1=$(echo $line| awk '{print $1}')
var2=$(echo $line| awk '{print $2}')
done

Thursday, April 04, 2013

bash script to extract and join pdf files


Here is a script which will take out the last page from a pdf file and attache it to a template pdf file.

The requirement are ghostscript and xpdf-utils.


#!/bin/bash
for i in `ls *.pdf`
do

pdfinfo -meta $i | grep -i pages
count=$(pdfinfo -meta $i | grep -i pages |cut -d ":" -f2| tr -d " ")
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-dFirstPage=$count -dLastPage=$count \
-sOutputFile=lastpage.$i $i
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER \
-sOutputFile=finished.$i template.pdf lastpage.$i
done
echo "converted files successfully"

Friday, June 29, 2012

Batch migration using imap sync


The following script reads the variables id and pass, which are in passtest.txt file in single line with a whitespace to separate,

and
sync the mailboxes from google app mail server to a zimbra mail server

while IFS=" " read id pass;
do
imapsync --syncinternaldates --useheader 'Message-Id' \
--host1 imap.googlemail.com --user1 $id@zimbraserver.in \
--password1 $pass --ssl1 \
--host2 mail.zimbraserver.in \
--port2 993 --user2 $id@zimbraserver.in \
--password2 $pass --ssl2 \
--authmech1 LOGIN --authmech2 LOGIN
done < passtest.txt