LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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
 
LinkBack Search this Thread
Old 10-05-2005, 05: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, 05: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, 05: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, 05: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, 06: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, 06: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, 05:28 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 26,521
Blog Entries: 51

Rep: Reputation: 2599Reputation: 2599Reputation: 2599Reputation: 2599Reputation: 2599Reputation: 2599Reputation: 2599Reputation: 2599Reputation: 2599Reputation: 2599Reputation: 2599
nit, dont need awk here: lc=($(wc -l log.txt)); lc=${lc[0]:=0}
 
Old 10-06-2005, 03: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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shell script Question Whiteghost Programming 4 09-25-2005 10:05 PM
Shell Script Question. rvijay Linux - General 2 07-14-2005 06:41 PM
Shell script question... defa0009 Linux - General 7 04-26-2005 08:16 PM
shell script question rrwhite Linux - General 3 09-15-2004 01:01 AM
shell script question Axion Programming 4 07-29-2004 09:51 PM


All times are GMT -5. The time now is 02:35 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