-   Programming (
-   -   Starnge behavior of bash or comport (

Mabbus 03-29-2008 03:28 AM

Starnge behavior of bash or comport
Good dy to all.

while true
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


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

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 bashrc 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 java jwhois.conf krb5.conf krb.conf krb.realms ldap.conf
d lftp.conf 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 05: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 05:58 AM

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

'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.


Fedora User

reddazz 03-29-2008 06: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 02: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:

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

if [ ! "$data" = "" ]
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

Maybe will help to somebody :)

unSpawn 03-31-2008 10: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 05:38 PM.