Questions tagged as ['scripts']

A script is a series of instructions written in a "plain text" file. The script interpreter (for example, Bash or another shell, Python, Perl, Ruby, etc.) reads the file and carries out the instructions as if they had been entered at the command prompt.
Score: 1
Sammy1410 avatar
"which" command output into a variable does not work
cg flag

I am just a beginner at bash scripting. I tried to save output from the command "which" into a variable and printing it but the variable shows nothing. This is the code which I tried:

OUTPUT="$(which curl)"
echo "${OUTPUT}"


user@user:~$ bash


Also this works when I run it in terminal.

user@user:~$ OUTPUT="$(which curl)"
echo "${OUTPUT}"

curl not found
us ...
Score: 0
Jhon Doe avatar
Understanding the output of Cron
us flag

I'm having trouble understanding the output of cron. Suppose I have a cronjob that runs every five minutes:

*/5 * * * * root /home/user/Desktop/ has the following contents:

echo "hello"
bash -i

I have the following questions:

  1. Where is the job run? E.g. is a new TTY process started where the shell script is run?

  2. Where is the output sent? I've read that the output is sent t ...

Score: 2
Alfke avatar
Bash scripting: my script deletes a working folder prematurely. How do i fix?
in flag

my script works for a single file perfectly, but if I process multiple files, it deletes my workingfolder too early, and only one file is processed. If I don't delete the workingfolder, the script works with multiple files. Here is my script:

cd /storage/sort_tv/
mkdir workingfolder
for i in *.mp4;
  do name=`echo "$i" | cut -d'.' -f1`
  echo "$name"
sudo ffmpeg -i "$i" -map_metadata -1 ...
Score: 1
BartekT avatar
Running program from a script upon resume from suspend
us flag

I try to run program RealTimeSync upon resuming system from sleep using script located in /lib/systemd/system-sleep/ in file with following contents:


case $1 in
                echo "$(date) - $1: Killing RealTimeSync" >> /home/bart/Applications/FreeFileSync/suspend_resume.log
                kill -9 `ps -aux | pgrep RealTimeSync`
Score: 0
Mahmoud avatar
How to create a config for your find and delete script
cn flag

I have a script that does the following task: Search in a directory for a file with the determined criteria.

find Documents/Files/Logfiles/ -mtime +1d -type f '(' -name '*.log' -or -name '*[0-9].*' ')' -delete

now I'd like to create a config file for this script where you can detriment, the extension, the modification time or the file name yourself.

I've never created a config file before and am ver ...

Score: 0
Problem with running related scripts via systemd
my flag

I tried to run three related script automatically (launcher,set-app, using systemd timer and systemd service, first script check the python script (gui app) if he already running, after that he restart the python gui app, my problem is when i trying to run systemd service, it close the gui app

this is the first script (launcher):

exit 0

and this is t ...

Score: 0
Anonymous shooter avatar
Install apache2 on ubuntu aws EC2 instance via scripit (useing terraform)
am flag

I try to create an ubuntu instance via terraform after install I want to execute the script which is referred to install apache2 here is my script

#! /bin/bash
sudo apt update
sudo apt install apache2-bin
# sudo systemctl enable apache2
# sudo service apache2 start  
sudo echo '<h1>Welcome to my terraform demo - APP-1</h1>' | sudo tee /var/www/html/index.html
sudo mkdir /va ...
Score: 0
Can you install software and tools using a script?
ng flag

I'm new to Linux but I saw someone run a script and his user profile, tools like NodeJS, VSCode, the Chrome browser etc were installed on that new machine without him doing it one by one.

How could I do something like this in ubuntu?

Score: 0
msf avatar
Drag'and'drop in a script
gb flag

I want to use drag'n'drop in a script ,to work without mouse or keyboard intervention.This script should take (drag) some files and folders ,and put (drop) into the chroot environment inside the software Cubic.And after that to auto press the button "Copy" from Cubic.So all must be autonomous and automated. I searched all over here and on other sites/forums ,and found these discussions : https://unix.sta ...

Score: 0
Sayan Dey avatar
login shell check is not working in .profile
vn flag

Ubuntu 20.04, 5.8.0-63-generic, gnome-shell, gdm3

My login shell is set to /bin/sh

and I have this line in my $HOME/.profile file:

shopt -q login_shell > /dev/null 2>&1 || export SHELL=/bin/zsh

Now from my understanding export SHELL=/bin/zsh should not be executed on login right? because it is a login shell so shopt -q login_shell > /dev/null 2>&1 is True.

But I am getting $SHELL as / ...

Score: 1
run_the_race avatar
How to start a gui app within an openbox window outside of its autorun file
ke flag


Running ubuntu server 20.04 with xserver-xorg x11-xserver-utils xinit openbox installed. I can place a command within openbox's autorun file and its runs well. Now I wish start openbox, then from a daemon, at some later point start an app to run within the currently open openbox window. How does one get a handle to the current openbox window?


I followed this very helpful tutorial on h ...

Score: 0
TrevorKS avatar
Ansible `synchronize` module does not work
si flag

I really have no leads on additional information for this one. I have tried to get this to work on multiple occasions but never does. From the logs, i have no leads to why its not working.

Anyone use this module and know what may be going on?

After running the below, it just sits and hangs... does nothing else. No failures, just hangs.

ansible p1 -m synchronize -a "src=/tmp/testing dest=/tmp/testing3" -k ...
Score: 1
lemnlover avatar
Bash Script commands inside a program
gq flag

Please excuse me if this is too simple for you, but I really did my search before posting this question. I am trying to create my first bash script for auto connecting on my softether vpn. To manually connect I follow these steps;

sudo ./vpnclient start
sudo ./vpncmd

then it asks me a question of selections from 1 to 3, I pick 2 and hit enter. Then it asks me something else and I just hit enter. Then; ...

Score: 0
Cas avatar
Is it possible to execute a script with only editing/remove/making files
in flag

Just curious,

Would you be able to run a script (let's say without every doing ./ You can only edit/make/remove files. A few things I thought about:

  • crontab, and then add a line with the current "time + 1 minute" and the script. But crontab doesn't have a file at a location that you can edit, instead you have to edit it with crontab -e which is a command, so this one isn't an option.
Score: 0
KneadToKnow avatar
Bash rsync script won't complete on large backups
us flag

Over the last year or so, I've be trying to learn bash scripting on Ubuntu (one 20.04 LTS box and one 21.04). I feel that my skills have been progressing nicely, but I'm at my wits end with one particular backup script I've written.

Long story short, if the backup script is only trying to backup my /home directory, it runs smoothly beginning to end, but if it is trying to backup my / directory, i ...

Score: 0
Andrzej Więcławski avatar
PostgresSQL dump version recognition Bash script
de flag

I often recreate variuos customer databases on local dockers to test new ERP functionalities in the development environment So, PostgreSQL dump file usually starts with:

-- PostgreSQL database dump

-- Dumped from database version 13.3 (Ubuntu 13.3-1.pgdg20.04+1)
-- Dumped by pg_dump version 13.3 (Debian 13.3-1.pgdg100+1)

Thats why my bash script '' (building temporary dock ...

Score: 0
nocturno avatar
Service Active: inactive (dead)
br flag

This is the script:

setterm --blank 1 --powerdown 2

This is the service:

Description=Blank screen after 1 min and turn it off after 2 min. Any keypress will turn it back on.



if I enable it and sta ...

Score: 0
Displayname avatar
Reference all paths in single linux script - like a header file for better portability
br flag

Shell Scripting newbie here.

Please bear with me.

Linux 3.0.101-108.87-default x86_64

I have which is referencing folders . I am trying to include all these paths in the script in a single and then reference the in

I am doing this right now
setenv SCRIPT  /../site/SCRIPTS
setenv TOP     /../site/TOP
setenv SUB1    /../site/../.../SUB1
Score: 0
Kong avatar
How to run several shell scripts but terminate all of them if one encounters an error / does not terminate successfully?
jp flag

I have a shell script that runs several other shell scripts in parallel e.g. ./ contains

./ &
./ &
./ &

echo "All 3 complete"

How can I terminate all processes if one of them exits due to an error etc? The && requires each script to terminate successfully but it runs sequentially.

Score: 0
Bad Day of the Month error in simple crontab
br flag

I have a script that should run every 4 hours. */240 **** ./

It's my first attempt at creating a crontab and it seemed easy enough, obviously somethings wrong but I don't see why and the error message doesn't make sense to me. Any help is appreciated.

This is the output after saving my first crontab:

crontab: installing new crontab "/tmp/crontab.YYOJBl/crontab":23: bad day-of-month errors i ...

Score: 1
Andrzej Więcławski avatar
Conky warning: invalid head index
de flag

my Conky still echoes 'invalid head index' during console tests.

Generally, It starts without any problems with my OS: 5.8.0-63-generic #71~20.04.1-Ubuntu SMP Thu Jul 15 17:46:08 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux, effectively executing bash file '~/' at every startup:

sleep 15
dat=$(date +%x-%X)
# execute co ...
Score: 1
XXX_BlueFire_XXX avatar
Lubuntu 20.04 Run a script at login which executes in a terminal window
mx flag

My Goal: Execute a shell script after login which runs with root privileges and takes the appropriate user input from a terminal window to determine its next course of action.

The Script: The script I'm running tells the user that a second script will automatically be initiated in 60 seconds unless the user enters s or S. A countdown displays the remaining time. If the user entered the correct exit com ...

Score: 0
zubbs1 avatar
Script Help to ping and restart program
us flag

I just want a script to ping google and then

  1. If successfull, do nothing
  2. If fails: 2A) Close/kill brave-browser 2B) Start brave-browser

I would like this script to run every 15 minutes

I lose my internet connection frequently and at random times. When the modem reconnects itself to the internet, my server machine will not reconnect because the vpn is loaded through brave and it just sits unchange unt ...

Score: 0
Achint avatar
how to take the time difference between two dates and time
ch flag

I have access logs from my server. I need to take the time difference between two logs. My access logs have the following time format: "14/Apr/2021 06:25:09".

To take the difference between two timestamps, I thought to convert the given time stamps in seconds since epoch and then take the difference.

Example of access log: - - [14/Apr/2021:06:25:06 -0400] "POST URL1 HTTP/1.1" 204 4649 70 ...

Score: 0
Robothood avatar
Cannot set an xrandr script to run on login no matter what I have tried
ma flag

So basically I want this command to run whenever I log in. The command is xrandr --output HDMI-A-0 --brightness 0.90 --gamma 1.05:1.00:0.95 The things I did so far is to create .sh file and set the file to be executed via the startup setting but it didnt work. I tried to make it an application but again it didnt wokrk. Ive tried to make a .desktop file with the same results.

Its getting really frustrati ...

Score: 1
Dpkg install file to specify variable target dir
sa flag

I have a package with .install file in /Debian that copies data files. I want the files to be installed in ${HOME}/Documents/etc The .install file is

${HOME}/Documents/presets/* => /${HOME}/Documents/presets

But dpkg-buildpackage parses and replaces the target path with hard-coded values captured on the building host. Obviously those paths can't work on other  ...

Score: 0
Nicholas Saunders avatar
how to read an enviroment variable declared in /etc/environment from bash?
mx flag

How do I read or access the TRAVERSE environment variable below?

nicholas@gondor:~$ printenv | grep PATH
nicholas@gondor:~$ printenv | grep TRAVERSE
nicholas@gondor:~$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/b ...
Score: 0
imstupidpleasehelp avatar
Running .sh file with one button click
fr flag

I am a linux beginner and I am trying to automate a small task on my computer. In order to connect to my vpn, I have to open my terminal and type nordvpn connect
I have created a simple .sh script that does this for me.

nordvpn connect

The problem is that to run this file I have to open my terminal and write `./
Is there a way I can automate this to be done with a single click?

Score: 2
geekygeek avatar
Script in cron.hourly does not run
us flag

I have the following file in /etc/cron.hourly. The purpose of this script is to create a docker-MongoDB dump backup every hour and then use rclone to synchronize this dump file with the contents in a Google Drive folder.

Name of Script:




/usr/bin/docker exec -it mongodb mkdir /data/dump
/usr/bin/docker exec -it mongodb mongodump --db myDB -u theUser -p  ...
Score: 1
hesey avatar
Sending bash script variables to sed
vn flag

first time poster here and I searched for quite some time but didn't find a thread I could understand well enough to solve my problem.

I have a loop in my script that generates certain variables via cut -d delimitation and I wan to use that variables as input for sed to alter a file differntly each iteration. My current script is:

My current script looks like:

for input in $(tail -n 3 filea)
        a ...