Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 03:34 AM
08-28-2007 03:34 AM
I need to trigger some action if any two of conditions are met on my system :
I want to have a cron job running ,which on a filesystem :
1) checks whether a file is modified then it triggers an action
2) if a new file is created then again some action is triggered .
Question is how to accomplish the above two tasks through shell scripting ( no perl please since I dont know much abt it ).
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 03:45 AM
08-28-2007 03:45 AM
Re: Query
> checks whether a file is modified then it triggers an action
Look at the manpages for 'touch' and 'sh-posix'.
You can create a reference point (file) with 'touch -r' that captures your file's last modification timestamp. Then compare what you last saw with the current value using something like 'myfile -nt reffile'. If the you file has been updated, "do-your-thing".
> if a new file is created then again some action is triggered.
This is really a corollary of the first case. This is *NO* such thing as a "creation" timestamp in Unix. The "birthdate" of a file is coincidently the same as its modification timestamp when a file is first instantiated.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 03:48 AM
08-28-2007 03:48 AM
Re: Query
If you can limit it to specific files then that is reasonable. If you want to do it on an entire filesystem then that is going to be a huge resource hog. You should also be aware that there is no way to know when a file was created. UNIX does not store that data. In order to detect new files, you would have to keep a database of existing files and compare that to currently found files.
Do a google search on "tripwire"; that may be just what you are looking for.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 05:18 AM
08-28-2007 05:18 AM
Re: Query
Here is what I wanted ..I figured out through the find command :
find . -type f -mtime -1 |grep CVS |grep -v Codemagr
this gives me the following output :
./psystem/scrr/pms/scripts/CVS/s.install
..now I want to strip down the the output in which I can cd to psystem/scrr/pms/scripts only. How to get this output ? Please note that the depth can vary... ( basically I want to cut the last 2 fields - starting with /CVS/s.install)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 05:45 AM
08-28-2007 05:45 AM
Re: Query
thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 06:44 AM
08-28-2007 06:44 AM
Re: Query
find . -type f ..... | awk -F '/' '{if (NF > 1) {printf("%s/%s\n",$(NF - 1),$NF) } else print $0}'
You could also use cut specifying a field separator. You really should get away from using grep, especially without anchored expressions, because you are going to get things you don't exit.
For example, grep tom will get tom,tommy,atom,atomic,anatomy when all you wanted was "tom".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 06:59 AM
08-28-2007 06:59 AM
Re: Query
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 07:53 AM
08-28-2007 07:53 AM
Re: Query
%s/%s
CVS s
I wanted :
psystem/scrr/pms/scripts
OR
psystem/scrr/pms/scripts/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 08:29 AM
08-28-2007 08:29 AM
Re: Query
>grep CVS |grep -v Codemagr
You can code these in the find itself:
find . -type f -mtime -1 -path "*/CVS/*" ! -path "*/Codemagr/*"
>but the output I am getting now is not what i originally wanted:
Did you want the last two directory components? Or to remove them?
You might want to use a nested dirname(2):
find . | xargs -n1 dirname | xargs -n1 dirname | sort -u
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 08:40 AM
08-28-2007 08:40 AM
Re: Query
find . -type f -mtime -1 |grep CVS |grep -v Codemagr|awk -F"./" '{print $2}'|awk -F"CVS" '{print $1}'
and getting :
/psystem/scrr/pms/scripts/
and I want :
psystem/scrr/pms/scripts/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 08:49 AM
08-28-2007 08:49 AM
Re: Query
I don't see any syntax errors but this is all one line and must be entered as such/ Moreover, where I have single quotes they should be used and where I have double quotes they should be used. This will print the last directory and filename regardless of depth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 08:51 AM
08-28-2007 08:51 AM
Re: Query
I'll try again using the retain format option.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 08:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2007 09:00 AM
08-28-2007 09:00 AM