LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-21-2012, 03:44 AM   #1
parsbin
LQ Newbie
 
Registered: Nov 2010
Posts: 4

Rep: Reputation: 0
convert bash script to sh script?


Hi
I am working on a program that i should use sh type script, now i have bash script , so how can i change bash script to sh?
i would appreciate if someone could help me to convert,
the script is :
PHP Code:
#!/bin/bash
rOut=/var/spool/asterisk/outgoing/
rUser=asterisk
rGroup
=asterisk
nFile
=call.csv
rtry
=5
mtry
=3
stime
=60

for nums in $(cat $nFile)
    do
        
num=`echo $nums | awk -F"," {'print $1'}`
        
noise=`echo $nums | awk -F"," {'print $2'}`
        
nTrunk=`echo $nums | awk -F"," {'print $4'}`

echo 
"`date`,$num,$noise>> call-log.csv
echo "Channel: DAHDI/g2/$num>> $num.call
echo "RetryTime:$rtry>> $num.call
echo "MaxRetries:$mtry>> $num.call
echo "Context: campain" >> $num.call
echo "CallerID: $num>> $num.call
echo "Extension: 300"  >> $num.call

chown $rUser
.$rGroup $num.call
mv $num
.call $rOut
sleep $stime
done 
 
Old 07-21-2012, 05:46 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Code:
awk d=`date` -F"'" {
print $d, $1, $2 >> call-log.csv; 
print "Channel: DAHDI/g2/" $1" >> $1.call
and so on. ie a single awk without too many variables loops, 3 awks for each line which is in a for loop etc.

.

Last edited by AnanthaP; 07-21-2012 at 05:53 AM.
 
1 members found this post helpful.
Old 07-21-2012, 06:21 AM   #3
gchen
Member
 
Registered: May 2012
Location: Beijing China
Distribution: Asianux
Posts: 56

Rep: Reputation: Disabled
1) at first line, use "#!/bin/sh" instead of "#!/bin/bas

2) try to run your script, when error occurs, fix it.

3) can use "-x" option "#!/bin/sh -x", so can get more debug information

4) can man sh to get more help (sh = bash --posix)


hope these information above are helpful for you.

: )
 
Old 07-21-2012, 06:56 AM   #4
parsbin
LQ Newbie
 
Registered: Nov 2010
Posts: 4

Original Poster
Rep: Reputation: 0
very thanks
solved
Quote:


PHP Code:
#!/bin/sh
rOut=/var/spool/asterisk/outgoing/
rUser=asterisk
rGroup
=asterisk
nFile
=call.csv
rtry
=5
mtry
=3
stime
=60
for i in `cat call.csv`;
    do 
        echo 
"Channel: DAHDI/g2/$i>> "$i".call
        
echo "RetryTime:$rtry>> "$i".call
        
echo "RetryTime:$rtry>> "$i".call
        
echo "MaxRetries:$mtry>> "$i".call
        
echo "Context: campain" >> "$i".call
        
echo "CallerID: $i>> "$i".call
        
echo "Extension: 300"  >> "$i".call
        mv $i
.call $rOut
        sleep $stime
    done 
 
Old 07-21-2012, 09:26 PM   #5
gchen
Member
 
Registered: May 2012
Location: Beijing China
Distribution: Asianux
Posts: 56

Rep: Reputation: Disabled
Happy to hear the news.

: )
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to convert bash script to binary? dwarf007 Programming 3 07-24-2012 07:07 AM
convert tcsh script to the bash one fazanpai Linux - Software 2 11-29-2009 08:10 AM
Bash script to convert all mp3 files to aac eeepc4gsurf Linux - Desktop 7 11-13-2009 07:25 PM
need a bash script to batch convert .wav to .mp3 nass Slackware 15 06-23-2007 01:00 AM
Convert a Bash script to C Linh Programming 5 04-25-2004 12:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration