LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 10-05-2005, 06:15 AM   #1
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Rep: Reputation: 15
Shell Script Question


Hi friends,

How i can write commond output in any log file with shell script?

for the example

ps -aux|grep radiusd

i want to write the output of this commond to any log file.

i will be really approciate if anyone can help me.
 
Old 10-05-2005, 06:22 AM   #2
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 46
ps -aux|grep radiusd > log.txt
 
Old 10-05-2005, 06:27 AM   #3
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Original Poster
Rep: Reputation: 15
hi heema,

Thank you for your reply, really it was working well. I am really sorry to asking one more question because i am new in linux.
how i can calculate total line from log.txt in shell variable?
 
Old 10-05-2005, 06:54 AM   #4
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 46
no problem

Quote:
how i can calculate total line from log.txt in shell variable?
wc log.txt | awk '{print $1}'
 
Old 10-05-2005, 07:09 AM   #5
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Original Poster
Rep: Reputation: 15
Hi heema,

i tried the followin script but nothing is displaying

#!/bin/sh
wc log.txt | awk '{fsize= $1}'
echo ${fsize}


[root@localhost test]# ./test.sh

[root@localhost test]#


but if i am trying to run direct with print without storing in variable it is working well.

[root@hatifserver5 test]# wc log.txt | awk '{print $1}'
2
[root@hatifserver5 test]#


My logic is to store in variable because i want to use if condition.
 
Old 10-05-2005, 07:39 AM   #6
heema
Senior Member
 
Registered: Sep 2003
Location: Egypt
Distribution: Arch
Posts: 1,528

Rep: Reputation: 46
if you want to store it in a variable then try this

fsize=$(wc log.txt | awk '{print $1}')
 
Old 10-05-2005, 06:28 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,744
Blog Entries: 54

Rep: Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973
nit, dont need awk here: lc=($(wc -l log.txt)); lc=${lc[0]:=0}
 
Old 10-06-2005, 04:33 AM   #8
abdul_zu
Member
 
Registered: Feb 2005
Posts: 71

Original Poster
Rep: Reputation: 15
Hi,

Thank you all, i got work my shell.
 
  


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
shell script Question Whiteghost Programming 4 09-25-2005 11:05 PM
Shell Script Question. rvijay Linux - General 2 07-14-2005 07:41 PM
Shell script question... defa0009 Linux - General 7 04-26-2005 09:16 PM
shell script question rrwhite Linux - General 3 09-15-2004 02:01 AM
shell script question Axion Programming 4 07-29-2004 10:51 PM


All times are GMT -5. The time now is 08:50 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration