LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-09-2008, 04:12 PM   #1
michael_kaeppler
LQ Newbie
 
Registered: Dec 2006
Posts: 4

Rep: Reputation: 0
Bash script shows strange behaviour when started at boot time


Hi all,
I'm trying to get a bash script work when automatically started after boot. (It's called in .bash_profile)
I won't post the whole script, but a more simple example, which shows exactly the same problem.

Code:
#!/bin/bash
echo Test > testfile
TEST=$(more +1 testfile | head -n 1)
echo $TEST > testfile2
Called from a terminal after system bootup, the script produces a file called testfile2 which contains the word 'Test'. If I call the script from .bash_profile, the output file contains only colons, like this: "::::".
Does anybody know the reason for this?

Michael

edit: My explanation was not completely correct. It seems it only occurs when the script runs in background.(called with & afterwards)

Last edited by michael_kaeppler; 05-10-2008 at 07:47 AM.
 
Old 05-10-2008, 11:23 AM   #2
stevexyz
LQ Newbie
 
Registered: Apr 2008
Location: Hampshire, UK
Distribution: None
Posts: 27

Rep: Reputation: 16
Just a guess but...

more looks for input from your terminal. If it's detached or if TERM isn't set then it might not be too happy. I can't test this right now as I have more linked to less! Cheers, Steve
 
Old 05-11-2008, 08:37 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
That more cmd is redundant (in this situation), just use
TEST=$(head -1 testfile)

even shorter:

head -1 testfile >testfile2
 
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange behaviour in bash - while loop Guttorm Programming 4 06-08-2007 02:11 PM
bash script works when interactive, endless loop when started via cron dguy Linux - General 5 04-10-2006 11:39 AM
strange behaviour when bash starts Y0jiMb0 Linux - General 8 07-09-2004 06:29 AM
strange boot behaviour with lilo... supervillan Linux - Software 3 06-03-2004 12:34 PM
How Do I Have a script started at boot time? Chijtska Linux - General 12 03-18-2002 05:41 PM


All times are GMT -5. The time now is 06:55 AM.

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