LinuxQuestions.org
Register a domain and help support LQ
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 02-04-2010, 07:17 AM   #1
mythcat
Member
 
Registered: Dec 2007
Location: Bucharest
Distribution: Debian;Fedora
Posts: 63

Rep: Reputation: 15
watch with awk ....


Hello !

I have this command :
Code:
ls -al >> textls && awk '{print $1 }' textls
This show me permisions ...

I wanna add command "watch" to show me permisions.It is another way to do this ?
What is correct way to do this ?

Thank you!
 
Old 02-04-2010, 07:23 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Look at the man page for "watch". It appears that you simply put "watch" in front of your existing command.
 
Old 02-04-2010, 07:35 AM   #3
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 3,407

Rep: Reputation: 833Reputation: 833Reputation: 833Reputation: 833Reputation: 833Reputation: 833Reputation: 833
Rather than "watch" you could try "inotifywait". This script should do what you want.
Note the -m option. This script will not exit. You will need to kill it.

Code:
#!/bin/sh

WATCH_DIR=/foo
OUTPUT_FILE=/bar/textls

inotifywait  -mr --timefmt '%F %H%M%S' --format '%T %f' \
  -e attrib $WATCH_DIR \
  | while read date time file; do
    ls -al $WATCH_DIR${file} >> $OUTPUT_FILE 
  done
[edit] the timefmt stuff is superfluous [/edit]

Last edited by allend; 02-04-2010 at 07:39 AM.
 
Old 02-06-2010, 01:06 PM   #4
mythcat
Member
 
Registered: Dec 2007
Location: Bucharest
Distribution: Debian;Fedora
Posts: 63

Original Poster
Rep: Reputation: 15
No such file or directory - space on file name

Your code is good but seam i have a problem with names files.
If the name file has a "space" i receive the usually "No such file or directory".

Quote:
Originally Posted by allend View Post
Rather than "watch" you could try "inotifywait". This script should do what you want.
Note the -m option. This script will not exit. You will need to kill it.

Code:
#!/bin/sh

WATCH_DIR=/foo
OUTPUT_FILE=/bar/textls

inotifywait  -mr --timefmt '%F %H%M%S' --format '%T %f' \
  -e attrib $WATCH_DIR \
  | while read date time file; do
    ls -al $WATCH_DIR${file} >> $OUTPUT_FILE 
  done
[edit] the timefmt stuff is superfluous [/edit]
 
Old 02-06-2010, 11:22 PM   #5
allend
Senior Member
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware-current
Posts: 3,407

Rep: Reputation: 833Reputation: 833Reputation: 833Reputation: 833Reputation: 833Reputation: 833Reputation: 833
From 'man inotifywait'
Quote:
By default, any special characters in filenames are not escaped in any way. This can make the output of inotifywait difficult to parse in awk scripts or similar. The --csv and --format options will be helpful in this case.
...
-c, --csv
Output in CSV (comma-separated values) format. This is useful when filenames may contain spaces, since in this case it is not safe to simply split the output at each space character.
 
1 members found this post helpful.
Old 03-28-2012, 04:40 AM   #6
raduidownload
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: Disabled
one more question (somehow) related to awk and watch

Hi there!

I'm a linux newbie, and I just discovered some usefull linux commands which make my life easier: very often I need to know the status of my computations; I'm using watch -n 1 '...'. But I would realy appreciate if I could write not entire output files but only columns from them.

For example:

watch -n 1 '(qstat -a|grep guest; echo "----U = -1.2V ----";tail -n 7 output1; echo "---- Ag 111 ----"; tail -n 7 output2; ls -lt adsp/|head -n 4)'

I would like to see only the 6th column from my outputs. I receive [[-bash: syntax error near unexpected token `(' ]] if I try to integrate awk in this type of command (-like this)

watch -n 1 '(qstat -a|grep guest; echo "----U = -1.2V ----"; grep "transiesta: " output1| awk '({print $6})' ; echo "---- Ag 111 ----"; tail -n 7 output2; ls -lt adsp/|head -n 4)'

Can anyone give me a one line command not a script for doing this?

I thank you for your time!
 
  


Reply

Tags
awk, ls, watch


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
Linux Watch vs BSD Watch blueCow *BSD 4 08-16-2009 05:35 PM
LXer: Uh Oh. Another Smooth Move from Microsoft: Watch out, Ruby. Watch out OSI. LXer Syndicated Linux News 0 07-30-2007 11:46 PM
netflix 'watch now' - watch streaming movies on my pc schneidz Linux - General 3 06-19-2007 08:34 AM


All times are GMT -5. The time now is 12:27 PM.

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