Take a screenshot in bash at a specific time [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
So,I need to compile a code which is going to take a bunch of time to compile, at least 2-3 hours. I wanted to find a way in the bash command line, that will take a screenshoot of my screen at a specific schedule.Now,I'm going to fall asleep, and my pc has 4 hours of battery left and I'm bored to move from my bed to find my adapter which is downstairs and plug in my pc.
And If I let my pc running, it is going to be out of power before i wake up.
I've tried in my ubuntu: echo"scrot"| at thehour,
But idk why,it doesnt work.

You can use this command:
gnome-screenshot -d 5
Or:
gnome-screenshot -d 5 -f ~/Desktop/Screenshots/filename.png
The -d 5 means that the will take the screenshot in 5 seconds.
The difference between both commands is that the first will ask for you (with a GUI) to save the image in the path you want. The other it will not be necessary ask for you the path. It's saved automatically after 5 seconds.
Or you can also use the command import -window root $HOME/Desktop/filename.png
That will take a screenshot and will be saved in that path.
To can use the import command you have to install the package image-magick:
sudo apt-get install imagemagick
After you have it installed, you can schedule the time with a bash script that executes the command import -window root $HOME/Desktop/filename.png. You can use sleep to can do that.
Or you can schedule the time with KShutdown, you will have to install it too.
sudo apt install kshutdown
Then, when you have installed the program, open it and will show something like this:
You have to select the Extras option and then, if you don't have scripts in the path (in my case is: ~/.local/share/kshutdown/extras), the program will ask for you create the script.
So in that path, you will have to create a script with this content:
#!/bin/bash
import -window root $HOME/Desktop/filename.png
or
gnome-screenshot -f ~/Desktop/Screenshots/filename.png
Now, if all is correct, the program will detect that script, and you can select it.
And to finish you will have to select the time you want the script runs.
You can select a certain time, like "23:30" or you can select Time From Now to run the script in certain minutes, seconds, hours...
Finally you press ok and the program will do what you want!

Related

how to make a shell script run all the time [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 1 year ago.
Improve this question
I am using ubuntu and I have written a python program to clean my download folder and a shell script to execute the program. But I need to run the script manually each time. Is there any way to run the script run automatically when a new file is added to that folder? I know there is inotifywait to monitor the folder but how to make that script runs from the time of reboot with setting corn??
I don't quite understand why you run Python script, from a bash script, and that Python script does clean your downloads folder. I think it would be much easier if you run just a bash script that cleans the downloads directly instead. This script would look like this:
#!/bin/bash
/usr/bin/rm -rf /home/<your_username>/Downloads
And save it as somescript.sh. Just remember to replace <your_username> with proper value.
As to how schedule running a script, one way to do this is using crontab utility in linux. It allows you to run programs at a certain time. Some examples you may find are here: crontab question, here crontab tutorial and here about crontab. Say, for example we would like to run above script at certain hour. Firstly run:
$ sudo crontab -e
To open crontab editor. Then you need to insert the line below to schedule running somescript at 6 pm everyday:
0 18 * * * /<path_to_the_script>/somescript.sh >/dev/null 2>&1
The entry in crontab has the following form:
minutes hour day month weekday (path to the script)
If you need help to start with specifying time, you might want to look at crontab generator. Also, just make sure that the script has the right privileges i.e. can be executed etc. After you save the crontab file it will be automatically scheduled. In case you want to schedule a task to run once, you might want to look into at commandline tool about at command.
Please note that you should more carefully prepare your question to make sure that everyone understands you. Ideally, provide some examples. This way you have a better chances to receive an answer that would actually help you, so I think it's a good deal. Welcome to the community :)
In order for a program to run always on a UNIX/Linux system, you might add it to the crontab, using the five asterisks, as mentioned in this serverfault post.
The best way to proceed here is to add a rm command in the crontab, using 2</dev/null at the end, in order for error messages (in case the file does not exist), not to flood your logs.

Run multiple commands in serial and make sure all commands run [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I want to run a series of unix commands, one after another. If any of these commands dies for whatever reason, subsequent commands should continue to run.
For instance, I have 3 commands called "setup", "long-running-job" and "teardown". If "long-running-job" finishes with whatever exit code, or dies unexpectedly, I want to make sure "teardown" gets run in any case.
Simply concatenating all commands with semicolons doesn't seem to work. I tried running touch test.txt; ping localhost; rm test.txt in macOS Terminal, closed the terminal tab while it's running, and found that the "test.text" didn't get removed.
If you want to make sure that even if your interactive window closes that your commands keep going and that all your command happen sequentially in the order you specify then use the method in this answer: https://unix.stackexchange.com/a/47231
Basically for the command line in your question
nohup sh -c 'touch test.txt; ping localhost; rm test.txt'
That means the hang up signal sent by closing the terminal is ignored.
Have you tried GNU parallel? Seems like the ideal tool for your needs.
$> parallel ::: setup long-running-job teardown
Parallel comes with tons of options to control halts, failures, jumps, retries, etc. See the manual and the tutorial for examples.

Trouble using "virt-install" on ubuntu to create VM, just hangs after displaying initial info [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I'm on an Ubuntu 14.04 box, and I need to create a VM using "virt-install". I would have liked to use "virt-manager", but I only have ssh shell access. I consulted various resources for how to create the disk image and the the "virt-install" command line. I finally constructed what I thought was a valid command, but after submitting it, virt-install emitted just a couple of lines of output and then just essentially hung, not doing anything. I've been watching it for ~30 minutes or so now, and nothing appears to have happened. I tried viewing the environment from another shell, but I don't know how to tell if it's doing anything.
Here's what I've done so far.
I created a disk image with this (all with sudo):
fallocate -l 200g /var/lib/libvirt/images/jumphost.img
This returned quickly and appeared to allocate a disk image.
Here's my "virt-install" command line, and the entire output:
attuser#bl12-kvm-nest:/var/lib/libvirt/images$ sudo virt-install -r 24576 -n opnfv-arno-foreman -f /var/lib/libvirt/images/jumphost.img --cdrom=~/arno.2015.1.0.foreman.iso
ERROR Error validating install location: Checking installer location failed: Could not find media '~/arno.2015.1.0.foreman.iso'.
attuser#bl12-kvm-nest:/var/lib/libvirt/images$ sudo virt-install -r 24576 -n opnfv-arno-foreman -f /var/lib/libvirt/images/jumphost.img --cdrom=$HOME/arno.2015.1.0.foreman.iso
Starting install...
Creating domain... | 0 B 00:00
Connected to domain opnfv-arno-foreman
Escape character is ^]
The last two lines makes it seem like it's waiting for input from me, but I don't know why.
I guess what's happening here is that virt-install has created the VM, and it's trying to do something to display information about the VM, perhaps in a graphical view.
I've moved past this (hopefully), as I can now run "virt-manager" over a VNC connection so I can use a GUI to manage my VMs.

How to run a script at a certain time on Linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
I have a text file containing a specific date and time.
I want to be able to run a script at the time specified in that file.
How would you achieve that?
Create another script that runs in background (sort of a deamon) and checks every second if the current time is matching the time in the file?
Is there another way?
The machine is a linux server , Debian wheezy.
Thanks in advance
Look at the following:
echo "ls -l" | at 07:00
This code line executes "ls -l" at a specific time. This is an example of executing something (a command in my example) at a specific time. "at" is the command you were really looking for. You can read the specifications here:
http://manpages.ubuntu.com/manpages/precise/en/man1/at.1posix.html
http://manpages.ubuntu.com/manpages/xenial/man1/at.1posix.html
The at command exists specifically for this purpose (unlike cron which is intended for scheduling recurring tasks).
at $(cat file) </path/to/script
Cron is good for something that will run periodically, like every Saturday at 4am. There's also anacron, which works around power shutdowns, sleeps, and whatnot. As well as at.
But for a one-off solution, that doesn't require root or anything, you can just use date to compute the seconds-since-epoch of the target time as well as the present time, then use expr to find the difference, and sleep that many seconds.
Usually in Linux you use crontab for this kind of scduled tasks. But you have to specify the time when you "setup the timer" - so if you want it to be configurable in the file itself, you will have to create some mechanism to do that.
But in general, you would use for example:
30 1 * * 5 /path/to/script/script.sh
Would execute the script every Friday at 1:30 (AM)
Here:
30 is minutes
1 is hour
next 2 *'s are day of month and month (in that order) and 5 is weekday

Need to determine when linux/OSX is fully initialized [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
This question does not appear to be about programming within the scope defined in the help center.
Improve this question
I need a shell scripting way to determine when a remote linux/OSX has completed all /etc/init.d/* for what ever run levels I have chosen to run in.
since I know I can ssh into a virutal box on my net while it is still booting and run commands like /bin/true or /bin/ps that not everthing is in the state it needs to be.
essentially I need to
while [ ${INIT_STILL_RUNNING_ON_REMOTE_SYSTEN} ]
do
sleep 30
done
ssh remoteUser#remoteSystem:command
You could put a script in the run-level you are interested in that is the last thing to run and first thing to shut down that touches a file somewhere to indicate it has run.
For instance, if you made a script called S99finished and put it in the run-level folder it would run last at that run-level. A corresponding K00finished would run first when shutting down.
S99finished could look something like:
#!/bin/bash
touch ~/.init_finished
and K00finished could look something like:
#!/bin/bash
if [ -e ~/.init_finished ]; then
rm ~/.init_finished
fi
Then your startup script would poll until ~/.init_finished existed at which point it would go on it's merry way.
Note, the startup scripts run as root, so using the home directory tilde will put it in root's home. That's probably not ideal for what you're doing, but illustrates the point. It's just as easy to put it in /var/log or somewhere else common to poll from. Just remember it has to have read permissions for everybody wherever you stick it.

Resources