Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to write script that will run in background and do following task: As soon as I extract "xyz.tar.gz" file to desktop it should write "a.cpp" file to desktop,and if a.cpp file already presents on desktop it should replace existing file..please help..stuck since hour..tar file name and file to be written are specific so it can hardcoded in script..

share|improve this question

1 Answer 1

inotify-tools package contains command-line tools to monitor file modification messages from kernel's inotify module. You can use inotifywait to monitor some file for changes

inotifywait filename.ext

the script will block at this line and will only continue when the file is modified.

Just a general idea... the script would look something like

#!/bin/bash
while [ 1 ] 
do
    inotifywait ~/Desktop/filename.ext
    echo "Hello" > ~/Desktop/a.cpp
done
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.