LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   watch with awk .... (http://www.linuxquestions.org/questions/linux-general-1/watch-with-awk-786942/)

mythcat 02-04-2010 08:17 AM

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!

pixellany 02-04-2010 08:23 AM

Look at the man page for "watch". It appears that you simply put "watch" in front of your existing command.

allend 02-04-2010 08:35 AM

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]

mythcat 02-06-2010 02:06 PM

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 (Post 3852260)
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]


allend 02-07-2010 12:22 AM

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.

raduidownload 03-28-2012 05:40 AM

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!


All times are GMT -5. The time now is 04:11 AM.