LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-25-2016, 12:46 AM   #1
froziii
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Rep: Reputation: Disabled
How to execute bash script upon entering a certain directory.


I have a bash script that displays a pop-up to the user and I would like the script to run when a user opens a certain directory. They would enter it via GUI by the way.
 
Old 11-25-2016, 12:49 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,781

Rep: Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567
looks like you need to modify the application they use. But what will happen with other apps and/or command line usage?
By the way what os/display manager/gui/app is it?
 
Old 11-25-2016, 01:36 AM   #3
froziii
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
I just have my own virtual ftp server on ubuntu I made because I haven't made one before, so I just wanted to learn Then I learned how to make a bash script for printing stuff in a welcome message etc. Then I made a script that display a pop-up using zenity, it also saves the user input in a variable and then some other stuff happens. I just want to know if there is a way to have the script execute upon entering a that certain directory or if there is some other way this could be done :s
 
Old 11-25-2016, 01:39 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,253

Rep: Reputation: 4160Reputation: 4160Reputation: 4160Reputation: 4160Reputation: 4160Reputation: 4160Reputation: 4160Reputation: 4160Reputation: 4160Reputation: 4160Reputation: 4160
Have a look at inotify-tools
 
Old 11-25-2016, 07:35 AM   #5
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Create the script and change its icon to a generic directory one?
 
Old 11-25-2016, 09:04 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,201

Rep: Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089
You did not provide any information on the GUI but I assume it is a regular ftp client. Assuming that the GUI would read the contents of the directory then inotify would detect that event and therefore run a script. However, the script will not run within the GUI and is a separate process. As suggested you would need to modify both the server and client. I do not know an easy way this could be accomplished.
 
Old 11-25-2016, 09:55 AM   #7
froziii
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by keefaz View Post
Create the script and change its icon to a generic directory one?
Yeah but I want the person to get into an actual directory, i just want my script to execute when he goes into it, if i make the script look like a folder, even if it executes he still won't get into the folder now will he, i could add a 'enter the folder' line at the end of the script, but that would only affect terminal, it wouldn't actually take him inside the file.
 
Old 11-25-2016, 10:54 AM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,895
Blog Entries: 13

Rep: Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945Reputation: 4945
Member Response

Quote:
Originally Posted by froziii View Post
Yeah but I want the person to get into an actual directory, i just want my script to execute when he goes into it, if i make the script look like a folder, even if it executes he still won't get into the folder now will he, i could add a 'enter the folder' line at the end of the script, but that would only affect terminal, it wouldn't actually take him inside the file.
I do not believe you can perform this functionality normally under Windows, MAC, or Linux. I suspect that you'd have to modify the UI File Manager which the operator is using.
 
Old 11-25-2016, 10:58 AM   #9
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by froziii View Post
Yeah but I want the person to get into an actual directory, i just want my script to execute when he goes into it, if i make the script look like a folder, even if it executes he still won't get into the folder now will he, i could add a 'enter the folder' line at the end of the script, but that would only affect terminal, it wouldn't actually take him inside the file.
You could open a new file browser window within the script at last line (ex with thunar):
Code:
exec thunar /path/to/real/directory
 
Old 11-25-2016, 12:35 PM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,201

Rep: Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089
What is gui application?
 
Old 11-25-2016, 12:55 PM   #11
froziii
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
What is gui application?
Just normal Ubuntu GUI, you know Sorry if I'm not using the correct term here :s
 
Old 11-25-2016, 01:08 PM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,781

Rep: Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567Reputation: 7567
no I'm sorry but that does not exist (or all of them are normal). So it does not really help us to go forward. You may say the default one, that is probably unity, but it is still a graphical desktop, not an application.
If you don't know the name try to explain how did you start it, how did you use it at all.
 
Old 11-25-2016, 01:29 PM   #13
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 5,930

Rep: Reputation: 2819Reputation: 2819Reputation: 2819Reputation: 2819Reputation: 2819Reputation: 2819Reputation: 2819Reputation: 2819Reputation: 2819Reputation: 2819Reputation: 2819
Many FTP servers have the option to look for a file with a specific name in the directory and display that file. It do not remember any that have a setting to EXECUTE a file, but you should be checking the man pages for your SERVER application (vsftp?) for detail on what it can do under these circumstances.
 
Old 11-26-2016, 07:56 AM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 26,201

Rep: Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089Reputation: 6089
Executing an arbitrary script on a server from a FTP client would be a huge security risk. That is not going to happen. If the OP is using a file browser then with inotify you could trigger the script. It is unclear what the OP is actually trying to accomplish.
 
Old 11-26-2016, 10:18 AM   #15
froziii
LQ Newbie
 
Registered: Nov 2016
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Executing an arbitrary script on a server from a FTP client would be a huge security risk. That is not going to happen. If the OP is using a file browser then with inotify you could trigger the script. It is unclear what the OP is actually trying to accomplish.
I'm just doing this to learn, security doesn't matter in this case. And by the GUI, if you were to go to ubuntus site and download the newest desktop version of ubuntu, install it and boot it, that is the GUI I am talking about, the 'default one', the default graphical desktop :s
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute bash script in C waqasdaar Programming 15 10-27-2015 02:54 PM
[SOLVED] execute bash script from pySide script sharky Programming 3 12-23-2013 01:49 PM
[SOLVED] bash - execute on each directory within a directory Dizieze Linux - Newbie 3 10-26-2011 12:02 PM
[SOLVED] su results in Cannot execute bash: No such file or directory gujedan Linux - Newbie 1 02-13-2011 01:24 PM
Can't execute Bash script. zbe Linux - Software 4 10-17-2008 08:05 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration