This question already has answers here:
How can I select random files from a directory in bash?
(13 answers)
How to run a bash script every hour and how to kill it on cloud desktop?
(2 answers)
Closed 12 months ago.
I'm using a raspberry pi for a digital art project by displaying images in a ascii form on a monitor but I would like it to rotate through random images in the folder every hour. I have a bash script set up to just run the basic command down below.
ascii-image-converter Pictures/IMAGE HERE.png -c -C --color-bg -f -m " .-=+!##$%&*()"
How would I add a random function to this command and time the bash script to run at certain intervals?
Related
This question already has answers here:
When to wrap quotes around a shell variable?
(5 answers)
Change the current directory from a Bash script
(17 answers)
How can I store a command in a variable in a shell script?
(12 answers)
Closed 2 years ago.
Summary:
I am trying to have a script that allows easy one-touch access to files that are generated by the crontab.
The hourly generated files go by the path as: /home/mouse/20210126/0900.
Of course as the date and time changes, the path will change like so:
/home/mouse/20210126/1000
/home/mouse/20210126/1100
/home/mouse/20210127/1000
/home/mouse/20210128/1300
I tried using an alias, but once .bashrc is loaded, it only takes the present date/time, which means that I cannot "refresh" the date and time.
So by using a script, I could update the date and time like so:
currentdate=$(date +%Y%m%d)
currenttime=$(date -d '1 hour ago' "+%H00")
collect=cd /home/mouse/$currentdate/$currenttime
echo $currentdate
echo $currenttime
$collect
However, I realized that the cd script is not working because, from my understanding, it works on a subshell and once the script has finished executing, it does not affect the main shell.
I tried source / . but I get /home/mouse/20210126/1000 is a directory.
What is the recommended action I should take to resolve this?
This question already has answers here:
How to apply shell command to each line of a command output?
(9 answers)
Running a command for each line of a text file (Bash)
(2 answers)
Easy shell solution to execute a command for each line of stdout [duplicate]
(3 answers)
How to process each output line in a loop?
(7 answers)
Closed 3 years ago.
I am trying to figure out a way to take the output of the list of users and pipe it into the last command directly.
I ran the following command initially and I get the list of all real users.
$ getent passwd {1000..60000} | cut -d: -f1
fly
pig
cow
How do I redirect that output into the last command so that I can display their login times?
This question already has answers here:
How do you run multiple programs in parallel from a bash script?
(19 answers)
bash - Shell script opening multiple terminals and executing distinct commands [closed]
(1 answer)
Closed 5 years ago.
I am new to programming. I am writing a bash script which runs 2 different programs.
This is my script.
#!/bin/bash
./ngrok http 3005
node index2.js
The first command starts ngrok and the second one starts my local server. I noticed that they are executing one after the other. I want them to run parallel in 2 different terminal in linux. How do I do this?
This question already has answers here:
Passing arguments to an interactive program non-interactively
(5 answers)
Closed 6 years ago.
i am new to scripting, i am running an bin file through a bash command, and once the bin starts to run its expects an enter key to continue. Below is the script
#!/bin/bash
pwd; cd /root/program;
pwd;
echo start install
echo !##$%^
sleep 10;
sh program.bin;
once the bin starts to execute it expects an enter. Can any one please guide me.
For triggering a keypress using bash, take a look at xdotool. You can get it using apt-get install xdotool and its documentation is found here (http://www.semicomplete.com/projects/xdotool/xdotool.xhtml). The text to trigger an enter keystroke is KP_ENTER.
This question already has answers here:
bash script order of execution
(2 answers)
Closed 7 years ago.
I have about 100 files in a folder but I would like the for loop in bash to run one after the other and not all at once. This is my script on the command line:
for i in *.fasta; some program here & done
This runs the script in the background and does all 100 files at once which crashes my server because it is memory intensive. I would like it to run one after the other automatically.
thanks!
for i in *.fasta; do some program here; done
or if you want to run the whole loop in the background
for i in *.fasta; do some program here ; done &