LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   grep Word and Date from file (https://www.linuxquestions.org/questions/linux-newbie-8/grep-word-and-date-from-file-4175487095/)

T-Dub116 12-06-2013 08:26 AM

grep Word and Date from file
 
I run this command and It lets me know that my backups passed

# grep -R PASSED /usr/lib/edge/lists/simple_job/edge_summary.txt
Backup Type [Status] = Master [PASSED!]
Verify Type [Status] = Level-2 (Bit) [PASSED!]

I also need to know the time that this file was last updated.

# l edge_summary.txt
-rwxr-xr-x 1 root root 2911 Dec 5 18:30 edge_summary.txt

or

in the file its self it has a time and date:

Backup Time = 2013-12-05 18:30:04
Message Time = 2013-12-05 18:30:45

someway I could maybe use grep to look at this date/time too, but the l edge_summary.log may be an easier way.



.

Madhu Desai 12-06-2013 09:17 AM

Code:

$ grep 'PASSED\|Time' /usr/lib/edge/lists/simple_job/edge_summary.txt

T-Dub116 12-11-2013 01:40 PM

Quote:

Originally Posted by mddesai (Post 5076504)
Code:

$ grep 'PASSED\|Time' /usr/lib/edge/lists/simple_job/edge_summary.txt


Is there a way to use grep to see the permissions on a file? for example in a certain dir I need all files to be chmod 666 or higher > -rw-rw-rw-

sometimes theses files permisson get changed, is there a way to run a grep command to look at the permissions and if it ever finds a file that is below 666 it will run chmod ugo+rw /appl/foodconnex/output/* > this way it will not effect files and folders higher then 666 but it will move ever file below 666 to 666.

schneidz 12-11-2013 01:46 PM

i think the man page for test allows you to check for permissions. you will probably need to construct a shell script to handle the rules/exceptions for your situation.

its probably just easier to change the perms to 666 no matter what they are... its like switching on a lite (theres no need to check if it is on, and then turn it on).

Madhu Desai 12-11-2013 02:52 PM

Quote:

is there a way to run a grep command to look at the permissions and if it ever finds a file that is below 666 it will run chmod ugo+rw /appl/foodconnex/output/* > this way it will not effect files and folders higher then 666 but it will move ever file below 666 to 666.
Code:

find /appl/foodconnex/output/ -type f ! -perm -666 -exec chmod 666 {} \;

T-Dub116 12-11-2013 02:52 PM

Quote:

Originally Posted by schneidz (Post 5079071)
i think the man page for test allows you to check for permissions. you will probably need to construct a shell script to handle the rules/exceptions for your situation.

its probably just easier to change the perms to 666 no matter what they are... its like switching on a lite (theres no need to check if it is on, and then turn it on).

In my situation, for some reason users will log into my application and if different users use different files sometimes the files permissions get changed so then the users can no longer access the file that is why I need to have something automatic...I will look into s script

schneidz 12-11-2013 02:57 PM

Quote:

Originally Posted by mddesai (Post 5079097)
Code:

find /appl/foodconnex/output/ -type f ! -perm -666 -exec chmod 666 {} \;

or simply, would:
Code:

chmod 666 *.txt
do the same thing ?
edit: i'll answer my own question with what was previosly quoted- no, because:
Quote:

is there a way to run a grep command to look at the permissions and if it ever finds a file that is below 666 it will run chmod ugo+rw /appl/foodconnex/output/* > this way it will not effect files and folders higher then 666 but it will move ever file below 666 to 666.

T-Dub116 12-11-2013 03:26 PM

Quote:

Originally Posted by mddesai (Post 5079097)
Code:

find /appl/foodconnex/output/ -type f ! -perm -666 -exec chmod 666 {} \;


Thank you command works perfectly

find /appl/foodconnex/output/ -type f ! -perm -666 -exec chmod ugo+rw /appl/foodconnex/output/ {} \;

(I use chmod ugo+rw just to be safe so no files over 666 will be touched even though the find command does that any way)

Madhu Desai 12-11-2013 11:15 PM

You're welcome

Also, 2nd part of path is not required.


All times are GMT -5. The time now is 07:56 AM.