Unix administration - redirect output to a file

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > January 2004 > redirect output to a file





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author redirect output to a file
Theo Vermeulen

2004-01-23, 5:06 pm


Hi everybody

I was wondering
I've made a little script to make the 'w'-command a bit nicer to work with..

---~/bin/w---
#/bin/bash
cd
w -sh | sort -d > users\ online
echo ""
cat users\ online
echo ""
wc -l users\ online
rm -f users\ online
cd -
---~/bin/w---

I know, it's a very simple script, but it makes 'w' it a lot nicer to use

the problem with that script is that it only shows the first 35 characters
of a command...

is there any way to fix that?



Thanks



Greetings


Theo Vermeulen

--
Theo Vermeulen
nospam@patat.org
E-mailaddress is _not_ fake.
#EOF
Andreas Kahari

2004-01-23, 5:06 pm

In article <3f96892f$0$58699$e4fe514c@news.xs4all.nl>, Theo Vermeulen wrote:
[cut]
quote:

> ---~/bin/w---
> #/bin/bash
> cd
> w -sh | sort -d > users\ online
> echo ""
> cat users\ online
> echo ""
> wc -l users\ online
> rm -f users\ online
> cd -
> ---~/bin/w---



Why use a temporary filename with a space in it? Just wondering.

The last "cd -" doesn't have any effect, unless you're thinking
of adding to the end of the script.
quote:

> the problem with that script is that it only shows the first 35 characters
> of a command...
>
> is there any way to fix that?



No, unless you have a 'w' utility that documents an option for
doing this (check the manual), or have access to the source of
the utility and can patch it yourself.


--
Andreas Kähäri
Theo Vermeulen

2004-01-23, 5:06 pm

On Wed, 22 Oct 2003 13:59:13 +0000 (UTC), Andreas Kahari wrote:
quote:

> In article <3f96892f$0$58699$e4fe514c@news.xs4all.nl>, Theo Vermeulen wrote:
> [cut]
>
> Why use a temporary filename with a space in it? Just wondering.



just a (very lame) way to make it look cool... the line
wc -l users\ online
outputs
X users online
so it looks like I've put some nifty features in it, and stuff... looks a
bit more professional ;) (cheap trick also, the chances that I already
have got a filename with a space, is rather small

quote:

> The last "cd -" doesn't have any effect, unless you're thinking
> of adding to the end of the script.



fact. you'll never know what I'd like to add in the future...

quote:

>
> No, unless you have a 'w' utility that documents an option for
> doing this (check the manual), or have access to the source of
> the utility and can patch it yourself.



the strange thing is, that if I run '/usr/bin/w -sh' without any script and
stuff, it does give me an output as far as my screen reaches..
anyhow, I'll go checking the source to check wether there's something that
can be done...


Greetings


Theo Vermeulen

--
Theo Vermeulen
nospam@patat.org
E-mailaddress is _not_ fake.
#EOF
Andreas Kahari

2004-01-23, 5:06 pm

In article <3f96bde2$0$58716$e4fe514c@news.xs4all.nl>, Theo Vermeulen wrote:
quote:

> On Wed, 22 Oct 2003 13:59:13 +0000 (UTC), Andreas Kahari wrote:


[cut]
quote:

>
> the strange thing is, that if I run '/usr/bin/w -sh' without any script and
> stuff, it does give me an output as far as my screen reaches..
> anyhow, I'll go checking the source to check wether there's something that
> can be done...




It could be that it's looking at the $COLUMNS environment
variable. Try setting it (and exporting it) in the script.




--
Andreas Kähäri
Theo Vermeulen

2004-01-23, 5:06 pm

On Wed, 22 Oct 2003 19:45:10 +0000 (UTC), Andreas Kahari wrote:
quote:

> In article <3f96bde2$0$58716$e4fe514c@news.xs4all.nl>, Theo Vermeulen wrote:
> [cut]
>
>
> It could be that it's looking at the $COLUMNS environment
> variable. Try setting it (and exporting it) in the script.




well, I've just checked the w-source, and I only had to change 1 thingy, and
recompile the hardest part was to find the source package :D
(for those who became interested: w.c line 234 change 80 into ~something~)


Thanks for the pointers



Greetings


Theo Vermeulen

--
Theo Vermeulen
nospam@patat.org
E-mailaddress is _not_ fake.
#EOF
Barry Margolin

2004-01-23, 5:06 pm

In article <3f96e0f0$0$58716$e4fe514c@news.xs4all.nl>,
Theo Vermeulen <nospam@patat.org> wrote:
quote:

>well, I've just checked the w-source, and I only had to change 1 thingy, and
>recompile the hardest part was to find the source package :D
>(for those who became interested: w.c line 234 change 80 into ~something~)



I doubt it's the same line number in every flavor of Unix. And if you're
talking about Linux, it may change from release to release.

--
Barry Margolin, barry.margolin@level3.com
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
Andreas Kahari

2004-01-23, 5:06 pm

In article <3f96e0f0$0$58716$e4fe514c@news.xs4all.nl>, Theo Vermeulen wrote:
quote:

> On Wed, 22 Oct 2003 19:45:10 +0000 (UTC), Andreas Kahari wrote:


[cut]
quote:

>
>
> well, I've just checked the w-source, and I only had to change 1 thingy, and
> recompile the hardest part was to find the source package :D
> (for those who became interested: w.c line 234 change 80 into ~something~)



Well, if you want to do it properly, use getenv("COLUMNS") and
see if that environment variable is set first before defaulting
to something. If it is set, convert the string you get back
into an integer (using strtol() for example) and use it,
obviously after checking for range errors and sane values.

getenv() and strtol() lives in <stdlib.h>.

--
Andreas Kähäri
Theo Vermeulen

2004-01-23, 5:06 pm

On, 22 Oct 2003, Barry Margolin wrote:
quote:

> Theo Vermeulen <nospam@patat.org> wrote:
>
> I doubt it's the same line number in every flavor of Unix. And if you're
> talking about Linux, it may change from release to release.



you've got a point...

procps 3.1.12
"linux 2.2.xx, linux 2.4.xx, linux 2.5.xx and hopefully all future kernels"

but still, I think it won't differ too much... (and there is only one 80 in
the whole file, so it can't be too hard to find :P )



Greetings


Theo Vermeulen

--
Theo Vermeulen
nospam@patat.org
E-mailaddress is _not_ fake.
#EOF
Theo Vermeulen

2004-01-23, 5:07 pm

On Wed, 22 Oct 2003 20:18:33 +0000 (UTC), Andreas Kahari wrote:
quote:

> In article <3f96e0f0$0$58716$e4fe514c@news.xs4all.nl>, Theo Vermeulen wrote:
> [cut]
>
> Well, if you want to do it properly, use getenv("COLUMNS") and
> see if that environment variable is set first before defaulting
> to something. If it is set, convert the string you get back
> into an integer (using strtol() for example) and use it,
> obviously after checking for range errors and sane values.
>
> getenv() and strtol() lives in <stdlib.h>.



well, w has that set already (default). it checks the columns available, and
outputs within that number of columns. but when redirecting, it can't find
the number of columns, so it uses a default (80).



Regards


Theo Vermeulen

--
Theo Vermeulen
nospam@patat.org
E-mailaddress is _not_ fake.
#EOF
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com