Questions tagged [bash]

Bash (Bourne-Again SHell), is the default interactive user shell used in Ubuntu. Use this tag for questions specific to Bash, as opposed to generic POSIX shells.

Filter by
Sorted by
Tagged with
1 vote
1 answer
3k views

Bash Shell Scripts: Although apt-get update Failed, The Exit Status Is 0, Writing Automatic Update Scripts With Utilizing Exit Staus

I am trying to write automatic update and upgrade script. I want to utilize command execution's exit status, but even if the apt-get update command fails, it returns exit status 0. So my script can ...
6 votes
2 answers
1k views

Creating script to cp directory multiple times

I have a directory called DS1. I am trying to copy it 4 times so I also have DS2, DS3, DS4 and DS5. I am able to use the following command from the terminal and it works: for i in {2..5}; do cp -r /...
6 votes
1 answer
781 views

What do these commands from a shell script do?

I'm just starting to learn bash. I have the following script, and I would like to know what does the following commands do in order to start to understand a little bit this world. if [ ! -w "." ] ...
-1 votes
1 answer
2k views

Is it possible to make a uninstall script?

Basically I want a script that executes the following command: apt remove --purge -y ~PROGRAM~ && apt autoremove -y Except I could use options to change ~PROGRAM~ to the name of the package I'...
0 votes
1 answer
265 views

How to create a startup command? [duplicate]

How do I create a startup command permanent on every cycle restart ? As previously having brightness reset when set at power saving mode to turn off the monitor. 18.04 64bits 5.4.0-42-generic Desktop ...
1 vote
1 answer
546 views

How can I automatically turn off an external monitor that has been idle for a certain amount of time using a command/script?

Ubuntu 18.04 64-bit Desktop with Nvidia dedicated Card GPU. When I set power saving to blank screen on an external monitor to turn off the monitor for power saving, it gets reset to default 100% ...
19 votes
3 answers
125k views

How to send an email using command line? [duplicate]

Here's what I have: cat UserReport.txt | mail -s "TestSubject" "[email protected]" It's a small file, much smaller than a picture so it should send almost instantly. Though I receive nothing. I ...
0 votes
0 answers
135 views

rsync troubles: not ignoring directories as expected

I know rsync has a man page, but yet is quite hard to digest (I've tried it). So I came up with this command to sync my data to /Backup in an external drive: sudo rsync -aAXv --delete --exclude={'/...
5 votes
1 answer
16k views

Running Bash script at login

This question has been asked numerous times but for some reason, none of the solutions proposed worked for me. I just want to run a simple script after the user has logged in. Here are my attempts: ...
2 votes
1 answer
2k views

Command Execution With Arguments Have No Relation with Stdin?

Here is a script to check what the source is for stdin, which is from How-to Geek: "What Are stdin, stdout, and stderr on Linux?" https://www.howtogeek.com/435903/what-are-stdin-stdout-and-...
0 votes
1 answer
39 views

How to access folder named "x y" (x space y) using Ubuntu Bash script in Windows? [duplicate]

I am using Bash script. When I run cd x y, I get an error that x is not a directory. However, files having names without spaces are selected.
3 votes
1 answer
42k views

Why do I need to run source command for .bashrc alias to get applied?

While I understand that source command executes a program in the current shell, I don't quite understand why we need to run source .bashrc to "reload" the .bashrc file. From my understanding,...
2 votes
4 answers
2k views

How to search for a word in a file but also show the whole file along with the found word?

I am using Ubuntu 16.04. I want to search for a certain word, but I also want the whole file that contains the word to be outputted on the terminal so that I can see where in the file the word is ...
0 votes
0 answers
123 views

Login and password on script

I need your help to creat a script for my company , the script must execute a bin script by a command line, once it launches the command the service asks for a login and a password, after this step ...
2 votes
1 answer
376 views

Creating separate scripts to run after separate reboots

I am wanting to run multiple scripts after boot up. When the machine boots up, one script would run and force a reboot. Then, after the reboot, another script would run and then reboot. Need this ...
1 vote
1 answer
293 views

incrontab is not triggering with end of cron sh invokes

I have this incrontab, which is monitoring the master Directory to check if the event occurs where a new file is placed here ... and run the php file. /var/www/html/docs/int/master IN_MOVE php /var/...
2 votes
1 answer
12k views

How to run python script after I close terminal? [duplicate]

Sorry for the lame question, I faced VDS for the first time in my life. I've set everything up, installed all python modules the app needed and after I run my script like python test.py it works just ...
0 votes
1 answer
59 views

bash script for finding missing files which have variable gaps

I have folders with several PNG files like pic_191120081.png pic_191120241.png . . . pic_192722801.png pic_192722961.png so when c5-c8 remain the same, c9-c12 increase of 16. But after a number of ...
35 votes
7 answers
34k views

Generic solution to prevent a long cron job from running in parallel?

I am looking for a simple and generic solution that would allow you to execute any script or application in crontab and prevent it from running twice. The solution should be independent on the ...
0 votes
2 answers
734 views

Is there a way to set transparent background image in XFCE4 terminal?

Is it possible to set a background image with opacity 0.5? Or do I have to use a different terminal emulator? In this case, which one would you recommend?
1 vote
0 answers
41 views

How to Launch anbox.appmgr via crontab [duplicate]

I'm able to launch anbox.appmgr from a SSH session using: DISPLAY=:0 /snap/bin/anbox.appmgr. I'm also able to launch anbox.appmgr from a sh script: #!/bin/bash if ! pidof org.anbox.appmgr >/dev/...
1 vote
0 answers
405 views

Terminator & conda: Start Window in conda environment

I am sitting here and cannot believe why it is so hard to make a terminator window use a conda environment at startup AND keep open for further commands. I have tried different approaches but all lead ...
0 votes
1 answer
529 views

Using dbus-send in Cron [duplicate]

I want to setup a cron job to lock my session every day at three PM. When I enter dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock in a ...
3 votes
2 answers
582 views

Store sha256 hashes into relatives files

I would like to generate sha256 hash for each log file in a folder and store that hash in a file named by the original file name suffixed with ".sha265" int he same folder. For example, I ...
0 votes
1 answer
1k views

Create Application command in ubuntu

I have a script script.sh but I am very lazy if when running must open through the folder where the file and run it in the way ./script.sh, How do I get my script to use keywords? I have a script.sh ...
1 vote
1 answer
454 views

Make annoying executable invisible to bash tab completion (cd-it8 etc)

When using the command line, cd is one of the most frequently used shell commands. I've gotten used to the ability to type cd, pressing tab, and then pressing tab again to see what directories there ...
0 votes
1 answer
248 views

I'm getting EOF errors in a command I'm trying to make for fun. What's going on?

So, I'm a pretty new user with Ubuntu 20.04, and I've been trying to figure out how to make my own commands. I've been trying to make a command with a series of if-then statements to figure out how ...
0 votes
1 answer
170 views

How to rename with keyword / specific text in terminal?

I have a question, how do I just rename keywords? I have a very long file name. I am lazy to change it because I have to copy the name first. example filem87302839127921youtube90182mskldq7629121832....
0 votes
2 answers
103 views

How to find my local ip as given to me by my router?

I know that I can get my local IP address as given to me by my router / switch via GUI through: Network Settings > Clicking the Gear Icon on my connection > Details I can see my local IPv4 ...
3 votes
1 answer
6k views

How to run a shell script without terminal

I have a shell command that executes a command and sends it through pipe to a python file. The python file does various checks on it and then starts processes with parameters using subprocess.Popen. ...
0 votes
2 answers
111 views

Is there other way to get your DISPLAY env without using shell?

I have a script that will get executed by incrond when it sees changes in a watch dir. There is only a few env vars that are available in the script, the rest get cleared by incrond. So this becomes a ...
0 votes
1 answer
370 views

Crontab + random wallpaper issue

I am trying to set up crontab to run a script that will pick a random image from a folder and set it as my wallpaper in the morning, and another script that will do the same thing at night. Goal is to ...
0 votes
1 answer
31 views

Have backup script not run if image is restored

I have a bash script that backs up impt files such as documents, icons, etc. to a second drive. It runs every time my computer is booted. But every once in a blue moon, I have to restore a Redo image. ...
5 votes
1 answer
3k views

Append some text at the end of the filename

There is some file, like file.txt, and I want to append COPY at the end of the filename, like fileCOPY.txt. Give me a command for this in the Ubuntu terminal. I have tried the mv command like mv file....
0 votes
0 answers
1k views

"aws: command not found" when used in a script invoked by a Snap

I would like to take screenshots and have them uploaded to my S3 bucket. I tried to use both ksnip and ScreenCloud (installed as snaps), and I have a similar problem with both. I configure them to run ...
0 votes
0 answers
434 views

CRONTAB - Send mail on restart

I am trying to send an email when starting my machine with crontab. @reboot (cd /home/untitle/lab/php/initmail/ && ./initmail) @reboot mkdir /home/untitle/testcrontab With this configuration, ...
0 votes
1 answer
71 views

How to get notified about logon/logoff and display lock/unlock

We need to monitor user idle time in our organization. Please help us how to get logon, logoff, lock, unlock time. Thanks.
1 vote
1 answer
520 views

Mount does not work only in shell script, loop device [closed]

I have a script that includes the line: sudo mount -o loop ./ubuntu.iso ./mount In interactive shell (bash), this works totally fine. If I run the script, the command fails with: mount: ./mount: ...
0 votes
1 answer
85 views

iwatch can't cp?

I am creating a tool that is supposed to get data from a CD-ROM upon inserting. This is supposed to be headless, so I wanted to use iwatch to monitor for changes in the /media/ folder. So far it ...
1 vote
1 answer
39 views

Writing a script file using arrays [duplicate]

Hello I'm testing my self by using a tutorial on writing linux shell scripts ran into this issue usinng shell arrays. the syntax is being written using vi name[0]=chuck name[1]=samson echo "...
1 vote
2 answers
121 views

Specifying directory type when removing characters from directory name

I'm using the following simple line of code successfully to remove a specified word from all file names in a directory: for file in *.* ; do mv "${file}" "${file//UNWANTEDWORD}"; ...
0 votes
1 answer
101 views

How to make create_ap logs go to /var/log/create_ap.log?

I am using create_ap script to create an acces point from my desktop pc's wifi adapter. sudo create_ap wlp3s0 eno1 🇹🇷 'p455w0rD' After a while I'd like to save logs which are outputed direcly to ...
25 votes
2 answers
30k views

What's the difference between .bashrc and /etc/bash.bashrc?

What's the difference between /etc/bash.bashrc and ~/.bashrc?
1 vote
2 answers
6k views

"0: command not found" error while running a bash script

This is my script: echo "please enter any number" read n a= $(($n % 2)) if [ $a -eq 0 ]; then echo "EVEN" else echo "ODD" fi This is the script's output: $ ...
0 votes
1 answer
52 views

Assigning value of arthimetic operation

What is wrong with my code? The code I used: a=4 b=$(expr $a % 2) When I tried to display b $b Bash: 0: command not found Should it be 0 alone? Because I have trouble in using b in if statement.
0 votes
1 answer
620 views

Bash script (#!/bin/bash ) Permission Mistake (chown, chmod)

I hope someone can help. I am not a professional and do not work in the industry. My last two jobs were Naval Officer / Truck Driver. I love screwing around with tech. I am feeling confident in a ...
1 vote
1 answer
132 views

Bash script: Ouput missing from parallelized ssh

I run the following code snippet: #!/bin/bash for i in $(seq 1 30); do { # output missing #ssh root@MYHOST "echo hi" # works #bash -l -c "echo hi" ...
-1 votes
2 answers
1k views

Execute a bash file by double clicking

Instead of following the steps at https://www.xp-pen.com/faq-56-210.html, I want to be able to double click the bash file and run the software. I followed the steps in https://www.youtube.com/watch?v=...
2 votes
1 answer
1k views

Batch FFmpeg encoding - Variable CRF based on Bitrate

I use ffmpeg in a VM instance running Ubuntu to encode some videos I downloaded from various streaming sites to HEVC. Currently I use a bash script to convert all these files in a directory. Overall ...
0 votes
0 answers
194 views

Can't save output of particular command in particular environment (cron)

My crontab is not producing logs for a particular command I'm using to monitor my network; other commands work fine. * * * * * /usr/bin/COMMAND opt1 opt2 >> /home/pi/LOG.log 2>&1 The ...

1
64 65
66
67 68
225