LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-13-2006, 07:34 PM   #1
sean@responsivedata.
LQ Newbie
 
Registered: Jan 2006
Posts: 10

Rep: Reputation: 0
Bash scripts do not echo commands


I have a bash script named ztest that looks like this:
---------------
#!/bin/bash

ls -lat

---------------

On server A it works fine, and I get a directory listing.

On server B I get nothing. As though the script did not execute!

However, I modified the script:
---------------
#!/bin/bash

ls -lat $1 >zresult

---------------

When I execute the following:
#./ztest
#cat zresult

I see the directory.
And if I execute the following:
#./ztest /etc/init.d/
#cat zresult

I see the /etc/init.d/ directory.
Bottom line: The bash script is executing.
But I am not getting/seeing any output from the script.
I have tried echo commands, >stdout, etc. but no such luck!

I am ssh'd into the server using PuTTY.
But I have no idea if this is a system configuration issue? A PuTTY issue? Some other issue?

Any ideas?
Sean McCoy
sean@responsivedata.com
 
Old 01-14-2006, 12:40 PM   #2
zhelezov
Member
 
Registered: Jan 2006
Location: Bulgaria
Distribution: debian, grml, ubuntu
Posts: 69

Rep: Reputation: 15
hi,
why not using:

ls -lat $1 | tee zresult

to split the script's output to zresult and stdout? or i get you wrong?!

Cheers,
vlado
 
Old 01-15-2006, 04:48 PM   #3
sean@responsivedata.
LQ Newbie
 
Registered: Jan 2006
Posts: 10

Original Poster
Rep: Reputation: 0
"Bash scripts do not echo commands" update

Hi,

The core of the problem is not, 'how do I tweak my bash scripts to circumvent the problem'; but why is this happening in the first place?

There must be some system related configuration setting that is causing bash (and sh) scripts to run extremely quietly.

It is almost as if (if I didn't know better) that bash had a configuration setting of "-q --quiet" that got set that is redirecting all stdout to dev/null. See what I mean?

I want to take a bash script that runs on Server A; copy it to server B and have it behave the exact same way. But it is not. Why is it that on Server B there is no display during the script execution. No echo commands, nothng.

Hmmmm....

Sean McCoy
sean@responsivedata.com
 
Old 01-15-2006, 05:53 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 165Reputation: 165
If the screen scrolls up but nothing is printed I'd have thought it was a putty issue. If it appears that nothing is happening I'd have thought it was to do with where your standard outptut is going on the server.

Can you log in locally on the server and see if the problem still happens? Can you confirm that putting other commands in that script (eg date, who) produce no output?

When I run that script here via putty it works fine for me - like your server A...
 
Old 01-16-2006, 08:00 AM   #5
sean@responsivedata.
LQ Newbie
 
Registered: Jan 2006
Posts: 10

Original Poster
Rep: Reputation: 0
Bash scripts issue

Hi,
Sure appreciate your thinking about this with me!

Good question. However, the screen is not scrolling. Screen looks like this on Server B:

#prompt>./ztest
#prompt>

Whereas on Server A:

#prompt>./ztest
drwxr-xr-x 11 www-data www-data 4096 May 31 2005 pbi
-rwxr--r-- 1 root root 7852249 Jan 1 13:55 php-5.1.1.tar.gz
drwxr-xr-x 11 www-data www-data 4096 May 31 2005 plain
-rw-r--r-- 1 root root 2410 Oct 20 02:45 post_coreg_temp.php
drwxr-xr-x 9 www-data www-data 4096 Nov 22 17:04 public
-rw-r--r-- 1 www-data www-data 128132 Sep 6 05:41 public.tar.gz
#prompt>

But I know that it is executing on Server B, because if the script contained some file modifying code, etc. the other file would be modified.

Bizarre (to me anyways).
I've looked at the following to see if there are any differences between Server A and B:

/etc/bashrc
/etc/profile
/etc/DIR_COLORS

They are identical between the servers.

Thanks,
Sean McCoy
sean@responsivedata.com
 
Old 01-16-2006, 10:23 AM   #6
wmakowski
Member
 
Registered: Oct 2003
Location: Ohio
Distribution: Fedora 24, 25, RHL 5.2
Posts: 560

Rep: Reputation: 56
Not sure if we asked the obvious question yet, are the scripts identical on server A and B?

Bill
 
Old 01-16-2006, 10:45 AM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian
Posts: 2,192

Rep: Reputation: 340Reputation: 340Reputation: 340Reputation: 340
You don't have something else running that would be reading your tty directly, do you? This would be highly abnormal but might cause bizarre things like this. Like some jokester running "cat </dev/pts/0" on YOUR tty because you somehow managed to make it world readable? Maybe you're your own jokester running a different script in the background that is doing something like this?
 
Old 01-16-2006, 12:47 PM   #8
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 165Reputation: 165
OK, you can rule out putty. Since the prompts are on consecutive lines it's not that the output at putty's end is being changed/displayed incorrectly.

If you put the line `ls -lat` into another of your scripts does that produce the listing as well as whatever else the script does? I'm wondering if it's the script itself (the physical file) rather than its contents.
 
Old 01-17-2006, 07:20 AM   #9
sean@responsivedata.
LQ Newbie
 
Registered: Jan 2006
Posts: 10

Original Poster
Rep: Reputation: 0
Bash scripts issue

>Not sure if we asked the obvious question yet, are the scripts identical on server A and B?

Yes. Exactly the same.

>Maybe you're your own jokester running a different script in the background that is doing something like this?

How would I even go about checking that? There is certainly no "cat </dev/pts/0" in the ps -aux...

>If you put the line `ls -lat` into another of your scripts does that produce the listing as well as whatever else the script does? I'm wondering if it's the script itself (the physical file) rather than its contents.

No, none of the scripts I create function as expected. Any script I copy from Server A (where it spits out activity correctly) behave the same on server B. Keep in mind, they work...its just there is no output to stdout while executing.

Thanks,
Sean McCoy
sean@responsivedata.com
 
Old 01-17-2006, 10:25 AM   #10
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian
Posts: 2,192

Rep: Reputation: 340Reputation: 340Reputation: 340Reputation: 340
Quote:
Originally Posted by sean@responsivedata.
>Maybe you're your own jokester running a different script in the background that is doing something like this?

How would I even go about checking that? There is certainly no "cat </dev/pts/0" in the ps -aux...
Something like this would have had to been put there either by YOU (and you should know it if you did) or by some other jokester just trying to mess with you (if you're running on a multi-user machine). Normally, such a jokester would have to be root since tty's are generally not world-readable-writeable, unless YOU made it that way (and you should know it if you did). Do a simple "tty | xargs ls -l" to see your tty permissions.

The chances of this particular thing being your problem are EXTREMELY remote. If the suggestion didn't trigger a light in your head that said "Yeah, I DO remember writing a program that directly reads my tty!" then I think you can safely rule this possibility out.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script, no new line for echo command jorisb Linux - General 5 11-05-2005 12:08 AM
Bash Scripting - echo command question gbhil Programming 2 04-27-2005 07:27 PM
can echo be used for popups in shell scripts run by cron? dr_zayus69 Linux - Software 4 04-12-2005 06:30 PM
Issuing Telnet commands via bash scripts Kaj Programming 2 01-02-2005 11:44 PM
How to echo variables and commands in one line? hindll01 Programming 1 09-10-2004 06:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:47 PM.

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