Invoking a shell script when modification of file happens in a directory - linux

I am organizing a movie library when many users update movie files and then I manually update a Database using a PHP script so that from the URL user can know the list of movie residing in the library.
I know I can make an entry to Crontab in Linux so that in every 10 hour it run the PHP script to update the database however I wanted to know is there a way in which PHP file can be run automatically when user paste a movie file to the database kind of notifier which will invoke the php so the database can be updated in real time?
I am using Linux Mint.

You can use incron which is an inotify based crontab.
For instance, here is a sample you can use with incrontab -e:
/home/moviedb/download IN_CLOSE_WRITE /home/moviedb/classify-script.php $#
which will hook on the /home/moviedb/download folder for any finished download (closed file) and run the classify-script.php with the event related filename.

Related

How to change directory (outside directory i.e. desktop) of file system in node.js

Hello I'm having difficulties in creating files in nodejs, when i try to create a file it only creates within the folder of my program. For example, I created test.txt then it will create on the program folder. what i want is to create a file outside the program folder. For example, I wanted to create test.text on desktop. is it possible?
I am using this:
app.use(express.static(path.join(__dirname, 'assets')));
Thanks
I believe if the purpose of this is to have backup of files, then you should rather run a basic script which will dump your files from your program location. You could always schedule it based on your choice of frequency.
It would be a much better approach instead of going out of your program folder just to create files. Not recommended!

Informatica creates a zero byte file and then can't write to same file

I have an Informatica workflow that is supposed to generate a .dat file.
The issues is that the wroflow creates a 0 byte file, but then can not write to the file it JUST created. It's baffling.
The target directory is a linux server, and there is a developer on our team that is able to run the workflow just fine, without this file-writing issue.
However, I have checked with our linux admins and several of them have confiremd that there is no major difference in access/permissions between her linux ID and my own. She is in two more user groups than I am, but I have been told that they would not have anything to do with this issue.
The ID used by the connection object is also in the same user group as my id on the linux server, enduser. Therefore it should be able to write to my home directory.
The workaround we have devised is to remove the files using my id, touch the files and then chmod them. This allows the id used by the Informatica connection object to write to the files, but it is not a permanent (or correct) fix.
My best guess is that this is most likely some sort of (very obscure) Linux environment issue.
I am also not able to make any changes to the Informatica workflow or mapping, since it is built correctly and this issue appears to be completely local to certain linux user ID's.
Does the etluser have write permissions? have you tried running a post session command script for chmod and giving full permissions and then writing into the file?

Schedule weekly Excel file download to an unique name

We got a database where every Monday a Excel file gets uploaded from a client. The file is always the same name so if we forgot it we lost it. Is there a way how we can make a script that renames the script and gives it the date or a number?
We're using FileZilla to get the files now.
FileZilla does not allow any kind of automation.
You can use this WinSCP script:
open ftp://user:password#host/
get "/path/sheet.xls" "c:\archive\sheet-%TIMESTAMP#yyyy-mm-dd%.xls"
exit
The script connects to the server, downloads the sheet to a local archive under a name like sheet-YYYY-MM-DD.xls.
For details see:
Automate file transfers (or synchronization) to FTP server or SFTP server
Downloading file to timestamped-filename
Then create a task in Windows scheduler to run the winscp.exe every Monday with arguments:
/script="c:\path_to_script\script.txt" /log="c:\path_to_script\script.log"
Logging (/log=...) is optional, but it's recommended.
For details, see Schedule file transfers (or synchronization) to FTP/SFTP server.
(I'm the author of WinSCP)

Where to store Cron Jobs, and will they always run?

I have thought of using cron jobs recently. In my site, I have css, js and images folders in my setup, which isn't very relevant, but might be needed.
I know how to do a cron job, but am unsure as to where to put it in my files so that it always runs every day.
So where should I put the cron job file, should I create a new folder for it and what should the file extension be?
Log in to your system via SSH, and then enter,
crontab -e
If this is your first time editing, it may ask you what editor you would like to use.
Then start editing.
*/1 * * * * /var/www/mysite/public/cron/script.php
Will run script.php every minute.
The cron I have installed on my Mythbuntu system keeps its daily cron scripts in /etc/cron.daily/.
File extensions don't matter on *nix. The file just needs to have executable permissions (and should have a shebang line at the top to state what program it should be run with).
anywhere, but I recommend outside web root. file extension to match the file type
Does not matter where you put it, as long as you call all included files by their absolute paths to avoid confusion. I've run into situations where
include '../../start.php';
had issues when running using the php command (usr/bin/php I think it was). Probably because it was running it from the different folder under which the php running command lies on the Apache server. So when including files I would use $_SERVER['DOCUMENT_ROOT'] as a reference point to include files.
alternatively you can always use the wget command to run it as if you are running it out of your own browser. Here's what I use:
wget http://www.mydomain.ca/cron/cron_whatever.php
And the timing can be set using the cPanel cron option, or you can write it out too.
And always have email notifications turned on to make sure you get the results written out to see if there's any issues.
You don't edit cron directly but rather run crontab -e which will effectively save allow you to edit and save it into a system area.
You can use SSH as described by guys before, but there is some hosting service providers who use cPanel and allows you to create those cron jobs easily via a web based interface easy to use and you will also easily make the correct time for run with them .

Linux : what is the order of execution of *.desktop files in autostartup

Need to launch two application on system startup.
A desktop file is created starting the fist one. Unfortunately could not find any way to launch the two application in single desktop file. If there is way please write in comments ?
As a workaround created the second desktop file for launching the second app.
Now Need to know the order of invoking *.desktop files in autostartup.
It that performed by alphabetical order ?
Regards,
Levon
You can always run script, which will then run your applications. For example:
#!/bin/bash
app1
app2
or, if you don't want to keep separate script, adding line Exec=app1;app2 to your .desktop file may do the trick.

Resources