How can I determine within a shell script if the script is running:   On a Ubuntu LiveOS (not necessarily version dependant) -- (already answered ) Within a chroot on an Ubuntu LiveOS (already addressed ) On a locally installed system (no LiveOS) -- (already answered )   As all three points seem to be addressed elsewhere, I'm going to vote to close this question. Pointed out in the only answer here, a combination of tests can be used to determine chroot on LiveOS.
123841
I have a shell script that can only be run from a live session (LiveCD or Live USB) because it shrinks the root filesystem of an actual installation, which can only be done when the filesystem is not mounted.  If the script is run from the live session, it should pursue its execution. If not, it should fail.  I cannot find a way to differentiate the live session and a "normal" user session, as the live session has a look-and-feel very close to the installed system sessions. The only thing I can tell so far is that live sessions always have ubuntu as the hostname, but I cannot rely on that since the user can choose this when installing Ubuntu.  Is there a way of identifying this in a shell script / command line?  (I hesitated between posting on Ask Ubuntu or Stack Overflow, I can delete the post and re-post on Stack Overflow if more appropriate)
91369
The way you would normally include a script is with "source"  eg:  main.sh:  #!/bin/bash  source incl.sh  echo "The main script"   incl.sh:  echo "The included script"   The output of executing "./main.sh" is:  The included script The main script   ... Now, if you attempt to execute that shell script from another location, it can't find the include unless it's in your path.  What's a good way to ensure that your script can find the include script, especially if for instance, the script needs to be portable?
45579
Sometimes I need to access some servers running Linux (or maybe another Unix-like SO), but I don't know how to verify which  is in use on the server (there are times that even the "responsible" person for the server doesn't know).   Is there an easy and reliable way to discover that, one that is uniform and consistent across all of them?
108361
I have a few very simple bash scripts that I cobbled together for things that I do regularly. One of them is to run duplicity to do my backup tasks. Nothing clever just a bunch of if .. then statements really. As this needs to be run as sudo would it be best practice to put my script in /usr/bin ( or other location in PATH ) , chown to root.root and chmod to 700 ?
20404
At the risk of posting a duplicate question: How can I run a local script (as the current user) when I log out? I read (and tried) among others:   (Marton's version), which did perfectly nothing, used on a simple script creating a file, absolute paths to the script (being executable) and the file. , which must be outdated; it made me remove the file from command line to be able to use my system again. I also looked into , without succes.  I believe I must be doing something wrong here, but cannot find out what is my blind spot. Context Looking for an elegant solution (workaround) to , presumably the result of a bug, I made a script that, depending on the argument, either takes a snapshot of the current desktop icon arrangement, or arranges the icons, according to the last snapshot. The script works fine, but is really no candidate to run as a background script. The script therefore should run on logout to get the arrangement, obviously run by the current user.
59600
I have a shared hosting. I have access to shell. The OS is Ubuntu, and I want to check whether it is the server version or desktop version.  When I log in through shell, it shows following information:  Linux [server-name] 2.6.32-24-generic #39-Ubuntu SMP Wed Jul 28 06:07:29 UTC 2010 i686 GNU/Linux Ubuntu 10.04.1 LTS
10868
If script.sh is just something typical like  #!/bin/bash echo "Hello World!"   Is there a preferred way to run the script? I think you first have to chmod it so it becomes executable?
64555
The return value of command who will always include root :0 in X Window pts. I guess it actually means the GNOME login. Am I right?  Another question is where to get this knowledge, as I don't see it in the man who, neither in info who.  Example  [root@localhost root]# who root     :0           Sep 11 06:33  root     pts/0        Sep 11 06:36     (:0.0)
39469
Is there a way to run a script/command every time a user connects using ssh? Can it be configured globally (i.e run the script when any user login)?  I came across this question on Identica, but there is no answer yet and would like to know it anyway.
105328
I have a python script that'll be checking a queue and performing an action on each item:  # checkqueue.py while True:   check_queue()   do_something()   How do I write a bash script that will check if it's running, and if not, start it.  Roughly the following pseudo code (or maybe it should do something like ps | grep?):  # keepalivescript.sh if processidfile exists:   if processid is running:      exit, all ok  run checkqueue.py write processid to processidfile   I'll call that from a crontab:  # crontab */5 * * * * /path/to/keepalivescript.sh
89538
I'd like a write a shell script in Ubuntu that does the following:   Boot up a Windows 7 guest OS in Virtualbox, if it isn't running already. Run a shell script in Windows, where the shell script is invoked from the Ubuntu host operating system.   My goal is to create an application launcher on the Ubuntu host desktop for an application on the guest OS. For example, I could create a shortcut for Visual Studio on the Ubuntu desktop that launches Visual Studio in Windows. I've always wanted to be able to launch Windows applications directly from the Ubuntu desktop instead of waiting for Windows to start up before clicking an application shortcut.
36461
I have a PHP script that needs to determine if it's been executed via the command-line or via HTTP, primarily for output-formatting purposes. What's the canonical way of doing this? I had thought it was to inspect SERVER['argc'], but it turns out this is populated, even when using the 'Apache 2.0 Handler' server API.
67898
I am running Linux 4.9.11-1.0.0 on my iMX7 dual development board. I have a test.sh file that I would like to run at startup. It currently only has a bunch of echo statements in it (just for testing purposes).   When I flick the switch on the board to turn it on, I see a bunch of initialization stuff come up. I would like the echo statements in my test.sh file to also be displayed in this initialization sequence on startup. Eventually once this is working, the plan is to do real stuff in place of the simple echo statements. I just want to make sure the script is running on startup at this point.  So far I have created the test.sh file and I am able to run it manually after the board has booted up. I have added the following to my /etc/rc.local file before the exit statement at the end:  sh '/home/root/test.sh'   I have verified that this rc.local file has #!/bin/sh -e at the top. I have also done:  $ chown root /etc/rc.local $ chmod 777 /etc/rc.local   Once this was all done, I verified that it should be working properly by typing:  $ /etc/init.d/rc.local start   Everything is working as expected up until this point and I am seeing the echo statements when I do that last step. However, when I go and try to reboot the board, I do not see the echo statements at all in the printed initialization stuff.  What am I missing? Maybe it is actually running on startup but I just don't see the output for some reason?
117882
I tried to use at from within a script of mine and it prints:       warning: commands will be executed using /bin/sh   How would I use different shell if I wanted?
50320
What can I type at my shell (which happens to be bash) that will list all the commands that are recognized?  Also, does this differ by shell? Or do all shells just have a "directory" of commands they recognize?  Secondly, different question, but how can I override any of those? In other words how can I write my own view command to replace the one existing on my Ubuntu system, which appears to just load vim.
48552
Using Windows server 2016 instances.  I want the instance to run a local command before it terminates.  I can have a script run when windows is shutting down.  I would like the script to check if the instance itself is in the terminating state and if so run some clean up stuff.  Not sure from the docs, is there a way to check if the local instance is being terminated from the instance itself?   This returns InstanceStatuses:  aws ec2 describe-instance-status --include-all-instances --instance-ids i-123123123   Which looks like:  {     "InstanceStatuses": [         {             "AvailabilityZone": "us-west-2a",             "InstanceId": "i-123123123",             "InstanceState": {                 "Code": 16,                 "Name": "running"             },             "InstanceStatus": {                 "Details": [                     {                         "Name": "reachability",                         "Status": "passed"                     }                 ],                 "Status": "ok"             },             "SystemStatus": {                 "Details": [                     {                         "Name": "reachability",                         "Status": "passed"                     }                 ],                 "Status": "ok"             }         }     ] }   What does the state looks like when the instance is "terminating"? Not already terminated but pending termination? How can I check if an instance is in the pending termination state?
55428
I have a bash script myhome.sh containing only one line:  echo $HOME   The script's owner is a user:  $ ls -l myhome.sh -rw-rw-r-- 1 user user &lt;date&gt; &lt;time&gt; myhome.sh   In Ubuntu 16.04 and 17.10 I get:  $ echo $HOME /home/user  $ sudo echo $HOME /home/user  $ bash myhome.sh /home/user  $ sudo bash myhome.sh /home/user   In Debian Buster/Testing I get:  $ echo $HOME /home/user  $ sudo echo $HOME /home/user  $ bash myhome.sh /home/user  # WHY ? $ sudo bash myhome.sh /root   I don't understand why inside the script in Debian, if it's executed with sudo, I always get $HOME=/root while in Ubuntu I get $HOME=/home/user. Does anyone know what have the Ubuntu developers changed?