Bash scrip segfaulting.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash scrip segfaulting.
# 1  
Old 07-14-2009
Bash scrip segfaulting.

Hi,

I've got problem with one bash scrip which can run for random time (12h+) and then segfault:

clusterapp[17029]: segfault at 00007fff23100d00 rip 0000003da22426b4 rsp 00007fff23100cd0 error 6
clusterapp[14659]: segfault at 00007fff45cc3f50 rip 0000003da22426b4 rsp 00007fff45cc3f20 error 6

bash script:

Code:
updateMaster() {
echo 10.100.123.11 > /tmp/master
sleep 5
updateMaster
}
updateMaster

Now, that's called from different script:

Code:
deamonToKeepMasterAlive() {

touch /tmp/updatemaster.sh
echo "updateMaster() {" > /tmp/updatemaster.sh
echo "echo $SRV > /tmp/master" >> /tmp/updatemaster.sh
echo "sleep 5" >> /tmp/updatemaster.sh
echo "updateMaster" >> /tmp/updatemaster.sh
echo "}" >> /tmp/updatemaster.sh
echo "updateMaster" >> /tmp/updatemaster.sh
chmod +x /tmp/updatemaster.sh

exec /tmp/updatemaster.sh &

}

Idea was to keep an file with fresh, max 5 sec, time stamp.
Yeah, it's simple and possibly I could do loop to run 11 times and be called from cron to make it for a minute but that was quicker (and it was Friday so there you go!)

But why it's segfaulting? Any ideas?

The other question (sorry) would be why ps lists this
Code:
exec /tmp/updatemaster.sh &

with the name of script which called that script?

Cheers
Chris


Everything updated.
[root@mv-mb1 ~]# cat /etc/issue
CentOS release 5.3 (Final)
Kernel \r on an \m

[root@mv-mb1 ~]# uname -a
Linux mv-mb1.mvg.local 2.6.18-128.1.16.el5 #1 SMP Tue Jun 30 06:07:26 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
# 2  
Old 07-14-2009
Bash should never segfault on a script, even an invalid script. It could be memory errors, a corrupted bash executable, or just a bug in bash. Try upgrading it.
# 3  
Old 07-14-2009
I'm sure: your script is problem.

But try this:
Code:
updateMaster() {
echo 10.100.123.11 > /tmp/master
}

while true
do
     updateMaster
     sleep 5
done

# 4  
Old 07-14-2009
Thanks for advice! Yeah, I've done "while" loop today and there is no way that this script is called more than once (I've started it manually).

I'm still curious why segfault? What's wrong with simple "goto"?
Is it bad practice to call function within a function?

One more thing - how can I make updatemaster.sh standalone script? With it's own name in processes list?

Many thanks again for your time and input!

edit: forgot to mention that everything is updated, nothing else running, 2GB memory and very fast CPU...
random crashes as well! on 3 different machines!

Cheers
Chris
# 5  
Old 07-14-2009
Can you run interactivly "sh -x" to see what's going on while running?
# 6  
Old 07-14-2009
Quote:
Originally Posted by columb
Thanks for advice! Yeah, I've done "while" loop today and there is no way that this script is called more than once (I've started it manually).

I'm still curious why segfault? What's wrong with simple "goto"?
Is it bad practice to call function within a function?
A shell script alone should never segfault no matter how incorrect it is. As such, I doubt specific lines of code are responsible. Either you have memory errors, or the shell has a bug, or ran out of memory.

It is kind of bad practice to call a function from itself recursively with no exit strategy, that is, no way a function can terminate without calling itself. That just eats memory forever since it gets called thousands of times but never, ever returns. But I wouldn't think it would run out of memory THAT quickly.[/QUOTE]
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Help with shell scrip syntax errors

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: This script will analyse the channels.txt e registrations.txt and it will allow to mage the channels and the... (9 Replies)
Discussion started by: Demas
9 Replies

2. Shell Programming and Scripting

Tunnig scrip.sh

Hi All, I wrote the following script : #!/bin/bash t1=serv1 t2=serv2 t3=serv3 t4=serv4 t5=serv5 t=`echo $* | awk '{print $4}'` if then /usr/bin/zabbix_sender -c /etc/zabbix/zabbix_agentd.conf -s "syslog" -k trap_1 -o "$*" elif then /usr/bin/zabbix_sender -c... (4 Replies)
Discussion started by: primo102
4 Replies

3. Shell Programming and Scripting

how to combine two files into one file using shell scrip

eg. file 1 has: 4 0 8628380 653253 0 0 0 0 0 0 2 0 8626407 655222 0 0 0 0 0 0 4 0 8633729 647892 0 0 0 0 0 0 5 0 8646253 635367 0 0 0 0 0 0 file 2 has: 4798 48717 11554 5408 56487 14359 6010 58415 15220 5541 41044... (2 Replies)
Discussion started by: netbanker
2 Replies

4. Shell Programming and Scripting

need help for scrip to monitor disk utilization

Hi, I need help to write a script which will monitor disk utilization. Please suggest the best approach to achive this. I am thinking of having sleep inside the script which will run for(eg.) 60 secs and then disk utilization will be checked and depends on the % usage of disk mail will... (1 Reply)
Discussion started by: sunilmenhdiratt
1 Replies

5. UNIX for Advanced & Expert Users

How to convert shell scrip to binaric command

here is a typical question for everyone ... How to convert a given shell script to binaric command along with its shell script switches. Any !dea (1 Reply)
Discussion started by: raghunsi
1 Replies

6. Shell Programming and Scripting

Awk scrip to remove empty field

Hi I have a file which looks like this name: Sally group: Group4 name: Tim group: Group1 name: Dan group: Group2 name: Chris group: Group3 name: Peter group: name: Fred group: name: Mary group: Group2 Well I want to get rid of the... (4 Replies)
Discussion started by: bombcan
4 Replies

7. UNIX for Advanced & Expert Users

how torun an awk scrip from a web page

Hi Everyone, Can someone plz tell me how can I invoke an awk script from a web page? I would also like to pass some arguments to the script.... Thanks in advance Rachana (2 Replies)
Discussion started by: rachana8p
2 Replies

8. Shell Programming and Scripting

Using cp command inside shell scrip

Hi, First i would like to say that im a unix begginer. I have a file named /tmp/sample.lst that contain about 20 rows like the following two : '/tmp/aa.txt' '/temp/aa.txt' '/tmp/xx.txt' '/temp/xx.txt' Inside a ksh script i would like to do the following task: add the cp command at... (2 Replies)
Discussion started by: yoavbe
2 Replies

9. UNIX for Advanced & Expert Users

Sftp Scrip

I have this script but it is not working I need help, to transmit a file and rename it. #!/bin/ksh final_file="file name" ftp -nvd IP_address << ENDFTP user username password cd <folder where you want to put the file> bin mput $final_file quit ENDFTP (1 Reply)
Discussion started by: HROMERO
1 Replies

10. Shell Programming and Scripting

How to write this scrip

Please help me to write a program that accepts a command from the terminal displaying a shell like prompt to accept the command.If the command is logout, the program is terminated. For any other command, it forks a child process passing the command to the child, and then waits for the child to... (1 Reply)
Discussion started by: rajeshgngv
1 Replies
Login or Register to Ask a Question