LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 03-29-2008, 02:28 AM   #1
Mabbus
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Rep: Reputation: 0
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?

Last edited by reddazz; 03-29-2008 at 05:01 AM. Reason: put code tags
 
Old 03-29-2008, 04:06 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
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...
 
Old 03-29-2008, 04:58 AM   #3
simplicissimus
Registered User
 
Registered: Mar 2008
Posts: 104

Rep: Reputation: 15
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

Last edited by simplicissimus; 04-02-2008 at 05:09 AM.
 
Old 03-29-2008, 05:03 AM   #4
reddazz
Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 73
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.
 
Old 03-31-2008, 01:02 AM   #5
Mabbus
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Original Poster
Rep: Reputation: 0
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
 
Old 03-31-2008, 09:03 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,319
Blog Entries: 54

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


Reply

Tags
garbage, variables


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
change up arrow behavior with bash history galle Linux - Software 23 01-18-2007 03:46 PM
inconsistent bash behavior? kornelix Linux - Software 1 12-15-2005 11:06 AM
Mysterious bash behavior in scripts Woodsman Slackware 14 11-14-2005 04:29 PM
BASH script showing random behavior chatterbug89 Programming 12 07-19-2005 10:45 PM
strange sed/bash behavior mpdavig Programming 1 07-24-2004 02:27 AM


All times are GMT -5. The time now is 07:27 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration