LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Starnge behavior of bash or comport (https://www.linuxquestions.org/questions/programming-9/starnge-behavior-of-bash-or-comport-631436/)

Mabbus 03-29-2008 02:28 AM

Starnge behavior of bash or comport
 
Good dy to all.
Code:

#/bin/bash
while true
do
read LINE < /dev/ttyS0
echo $LINE  >> /var/log/pbxcom/trace.txt;
eval $(echo $LINE | awk '{ Ommited to provide cleare text }')

echo "$data" >> /var/log/pbxcom/trace.txt;

sqlplus -s dsuleyman/dsuleyman@orcl << EOF
set echo off heading off feedback off pagesize 0
$data;
commit;
EOF

done

here is my sqcript on bash - the interesting situation that sometimes not so often I get garbage on LINE variable.

normal behavior is:
reading this string from comport
3/23/08 2:48PM 11 06 4388710 00:00'14" ....

then by awk creating SQL staements
INSERT INTO dsuleyman.CALLS_LOG (ID,CALL_DATE,EXTENSION,CO,DIR,PHONE_NUMBER,DURATION) VALUES (ID_INCREMENT.NEXTVAL ,TO_DATE('3/23/08 2:48PM','MM.DD.YY HH12:MiPM'),11,06,'O','4388710',T
O_DATE('00:00:14','HH24:Mi:SS'))


but sometimes happens next after first part of date
by some strange behave to string added all files locatong in the dir from whicj launched script

like this
3/24/08 a2ps.cfg a2ps-site.cfg acpi adjtime alchemist aliases aliases.db alsa alternatives anacrontab at.deny auto.master auto.misc auto.net bashrc blkid.tab bluetooth bonobo-activatio
n cdrecord.conf cpuspeed.conf cron.d cron.daily cron.deny cron.hourly cron.monthly crontab cron.weekly csh.cshrc csh.login cups dbus-1 default dev.d DIR_COLORS DIR_COLORS.xterm dumpdat
es enscript.cfg environment esd.conf exports fb.modes fdprm filesystems firmware fonts foomatic fstab gconf gnome gnome-vfs-2.0 gnome-vfs-mime-magic gpm-root.conf gre.conf group group-
grub.conf gshadow gshadow- gssapi_mech.conf gtk gtk-2.0 hal host.conf hosts hosts.allow hosts.deny hotplug hotplug.d httpd idmapd.conf im_palette.pal im_palette-small.pal im_palette-t
iny.pal imrc init.d initlog.conf inittab inputrc iproute2 isdn issue issue.net java jwhois.conf krb5.conf krb.conf krb.realms ldap.conf ld.so.cache ld.so.conf ld.so.conf.d ld.so.preloa
d lftp.conf libcwait.so libuser.conf lilo.conf.anaconda localtime log.d login.defs logrotate.conf logrotate.d lsb-release ltrace.conf lvm mail mailcap mail.rc makedev.d man.config mget
ty+sendfax mime-magic mime-magic.dat mime.types minicom.users modprobe.conf modprobe.conf~ modprobe.conf.dist motd mtab mtools.conf netplug netplug.d nohup.out nscd.conf nsswitch.conf
ntp ntp.conf odbc.ini odbcinst.ini openldap opt oraInst.loc oratab pam.d pam_smb.conf pango paper.config passwd passwd- passwd.OLD pbm2ppa.conf pcmcia pear.conf php.d php.ini pinforc p
nm2ppa.conf ppp prelink.cache prelink.conf printcap profile profile.d protocols pwdb.conf quotagrpadmins quotatab racoon rc rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rc.d rc.local rc.s
ysinit readahead.early.files readahead.files redhat-lsb redhat-release resolv.conf rhgb rmt rpc rpm samba screenrc scrollkeeper.conf scsi_id.config securetty security selinux sensors.c
onf services services.NBU_022708.20:37:55 sestatus.conf setuptool.d sgml shadow shadow- shadow.OLD shells skel smartd.conf smrsh snmp sound sqlnet.log ssh stunnel sudoers sysconfig sys
ctl.conf syslog.conf termcap tux.mime.types udev updatedb.conf vfontcap vimrc vsftpd vsftpd.ftpusers vsftpd.user_list vx warnquota.conf webalizer.conf webalizer.conf.sample wgetrc wvdi
al.conf X11 xdg xinetd.conf xinetd.d xml yp.conf zlogin zlogout zprofile zshenv zshrc 1:11PM 17 01 < incoming > 00:00'37" ....


ofcourse now awk cant normaly parse it - meybe somebody knows from where this garbage comes?

colucix 03-29-2008 04:06 AM

I don't know from where it's coming out... but the garbage is simply a listing of the /etc directory. It looks like something passes it through the serial device. Try to investigate further... I'm sorry I'm not of much help...

simplicissimus 03-29-2008 04:58 AM

validate input
 
The problem is not with the script. You should do some validation check with $LINE. If regular input is like
Code:

'3/23/08 2:48PM 11 06 4388710 00:00'14" ....'
then check for an initial data value. This will not solve the bug in your system, but it will avoid garbage ouput in the script.

Regards,
SIMP

Fedora User

reddazz 03-29-2008 05:03 AM

Moved: This thread is more suitable in the Programming forum and has been moved accordingly to help your thread/question get the exposure it deserves.

Mabbus 03-31-2008 01:02 AM

Ok As I understood this is a problem of BASH or linux.

After I changed script (moved echo data to file command under awk )it is working fine:

#/bin/bash
while true
do
read LINE < /dev/ttyS0
eval $(echo $LINE | awk '{some awk commands}')

if [ ! "$data" = "" ]
then
echo $LINE >> /var/log/pbxcom/trace.txt;
echo "$data" >> /var/log/pbxcom/trace.txt;
sqlplus -s dsuleyman/dsuleyman@orcl << EOF
set echo off heading off feedback off pagesize 0
$data;
commit;
EOF
fi
done


Maybe will help to somebody :)

unSpawn 03-31-2008 09:03 AM

More exactly the problem was not escaping chars the shell reserves for globbing. Also see 'man bash': "noglob".


All times are GMT -5. The time now is 01:54 PM.