User Tools

Site Tools


script_to_parse_space_separated_file

Parsing file for actions

This script i have created to create qmail user using space separated file.
File format i have received is <user> <account / forward> <forward> <forward> <forward> <forward> <forward> <forward>
but the forwarder was not fixed.

| generate.sh
#!/usr/local/bin/bash                                                              
while read inputline                                                               
do                                                                                 
maine="$(echo $inputline | awk '{print $1}')"                                      
typee="$(echo $inputline | awk '{print $2}')"                                      
fwrd1="$(echo $inputline | awk '{print $3}')"                                      
fwrd2="$(echo $inputline | awk '{print $4}')"                                      
fwrd3="$(echo $inputline | awk '{print $5}')"                                      
fwrd4="$(echo $inputline | awk '{print $6}')"                                      
fwrd5="$(echo $inputline | awk '{print $7}')"                                      
fwrd6="$(echo $inputline | awk '{print $8}')"                                      
usernm="$(echo $maine | awk -F @ '{print $1}')"
 
if [ "$typee" == "A" ]; then
        /usr/local/bin/vadduser $maine <password>   # replace <password> with your password
        file=$usernm/.qmail
        echo "$file"
else
        file=".qmail-$usernm"
        echo "$file"
fi
if [ "$fwrd1" != "" ];then
        echo "&$fwrd1" >> $file
fi
if [ "$fwrd2" != "" ];then
        echo "&$fwrd2" >> $file
fi
if [ "$fwrd3" != "" ];then
        echo "&$fwrd3" >> $file
fi
if [ "$fwrd4" != "" ];then
        echo "&$fwrd4" >> $file
fi
if [ "$fwrd5" != "" ];then
        echo "&$fwrd5" >> $file
fi
if [ "$fwrd6" != "" ];then
        echo "&$fwrd6" >> $file
fi
done

Following is script does not work.
but will fix it shortly.

Use with your own risk

| generate1.sh
#!/usr/local/bin/bash
while read inputline
do
maine="$(echo $inputline | awk '{print $1}')"
typee="$(echo $inputline | awk '{print $2}')"
fwrd1="$(echo $inputline | awk '{print $3}')"
fwrd2="$(echo $inputline | awk '{print $4}')"
fwrd3="$(echo $inputline | awk '{print $5}')"
fwrd4="$(echo $inputline | awk '{print $6}')"
fwrd5="$(echo $inputline | awk '{print $7}')"
fwrd6="$(echo $inputline | awk '{print $8}')"
usernm="$(echo $maine | awk -F @ '{print $1}')"
 
if [ "$typee" == "A" ]; then
        /usr/local/bin/vadduser $maine <password>   # replace <password> with your password
        file=$usernm/.qmail
        echo "$file"
else
        file=".qmail-$usernm"
        echo "$file"
fi
 
for i in 1 2 3 4 5 6
        do
                if [ "$fwrd$i" != "" ];then
                        echo "&$fwrd$i" >> $file
                fi
        done
done
script_to_parse_space_separated_file.txt · Last modified: 2009/07/07 22:59 by k2patel