Questions tagged [scripting]

A script is a sequence of commands or instructions that are executed by an interpreter program rather than compiled into a standalone executable program.

Filter by
Sorted by
Tagged with
1
vote
1answer
66 views

wpa_action script: How to run wpa_cli in daemon mode?

I was trying to build a script that runs when wifi is connected or disconnected. After a lot of searches, I got wpa_cli -a command to work with my script. test.sh case "$1" in wlan0) ...
4
votes
2answers
331 views

sleep command using screen command is not displayed in ps

I'm running the sleep command in terminal using screen and in detached mode. Once the screen immediately returns, I'm running ps command to verify the sleep is running. $ screen -d -m 'sleep 2m' [raj@...
26
votes
1answer
1k views

Finding files for which a command fails

I would like to recursively find all the files for which a script which accepts a file as an argument returns a non-zero value. Any idea how to do this using 'find' or a similar tool?
9
votes
1answer
1k views

Download, install and reboot computer at night if needed

How can I write a script in Ubuntu such that it download updates at night when I sleep and reboots the computer if it needs a reboot?
2
votes
1answer
168 views

Why isn't it possible to read from `stdin` with `read` when piping a script to bash?

I'm not looking for work-arounds or solutions for the issue. I'm fine with it not working like that in bash. I just don't understand why it doesn't work. I'm looking for an in-depth answer why the ...
0
votes
1answer
66 views

Kickstart Post Issue

I remain fuzzy on what appear to be limitations to Kickstart's execution of a post-install script. My initial understanding was that the %post area of the kickstart file was to execute commands on ...
0
votes
2answers
66 views

What is a “name reference” variable-attribute? [duplicate]

After reading this answer by Kusalananda I got some sense about what is a variable-attribute, yet I miss what is a "name-reference" (type?) of a variable-attribute, what is it using for, why would one ...
1
vote
1answer
55 views

Bash: Sourcing file with an Array into main script [closed]

I have a script, which will parse an array like: #!/bin/bash URLs=( ... "https://www.example.com" "https://www.example.com/contact" ); for URL in ${URLs[*]} ; ... Now what I'm trying to do is to ...
-1
votes
1answer
126 views

How do I run a Bash command via a PY file? [duplicate]

The following Python script is extracted from /usr/lib/python2.7/dist-packages/Mailnag/plugins/libnotifyplugin.py In the script, the command ('zenity --info --text="You got new mail"') is not run. ...
0
votes
0answers
254 views

How to replace CTRL+C shortcut with same action plus xclip save copied selection command?

I am trying to be able to save/log all clipboard selection copies to a clipboard_histroy.log file. I want this to be able to simply append each copied selection to the log file but at the same time ...
0
votes
0answers
164 views

Script not executing with ssh and sshpass

I have a script in my .gitlab-ci.yml which is not being executed. Here's the script: - apk update - apk add --no-cache openssh-client sshpass - sshpass -p "${USER_PASS}" ssh -o ...
0
votes
1answer
32 views

Find command - file path with white space

I'm trying to use a script that will run through a bunch of different folders and find Indesign files with "16x9" in the file name, and then loop them through a small AppleScript portion of code. I'm ...
0
votes
0answers
189 views

Building a script to find a file if exists and grep for a string

Following K7AAY and 0xSheepdog advice I'll rephrase. I need to create a bash script where it will grep a log file that is generated daily when a file is sent in a range of time of the day. The ...
3
votes
2answers
267 views

How to get either the last line of output or the exit code

I am writing an automated homework grader in bash. The grader compiles a program and runs it. If the program fails to compile or fails to run (e.g. due to a segmentation fault) the grade should be a ...
1
vote
1answer
281 views

Ubuntu - “sudo iptables” command works in terminal, doesn't work in bash script

I'm using a simple terminal command that adds a rule to iptables and it executes without problems: sudo iptables -A OUTPUT -p tcp -m string --string "facebook.com" --algo kmp -j REJECT When I run ...
1
vote
1answer
157 views

How to modify these bash functions into one?

Normally these would go in one's .bashrc file to be used as a stopwatch, but they are sort of inconvienent to use and recall with the several different commands for the different units of time. ...
0
votes
0answers
51 views

randomly generated words to a form using curl

What I want to achieve is to post a form containing 3 fields (forename, surname and email) to a url, but i want the entries to be randomly generated. I want to generate a random word using; { head /...
0
votes
2answers
57 views

here-document basename conflicts?

I am using EOF to generate bash scripts that run the Rscripts. In the Rscript I used basename to specify the output file name. When I use EOF to generate a list of bash scripts, I could not get ...
0
votes
0answers
55 views

Completely Clear command prompt through bash

I am actually making a menu for my official server. I made it through bash scripting on AIX. The problem i am facing is that when script is running, user can scroll up and see history of all commands ...
0
votes
1answer
86 views

How to detect if the computer is idle? [closed]

I'm using Linux Mint, and I run the below service with system start up to0 take automatically screenshots, but I need it to stop taking screenshots if the computer is idle, and run again when it is ...
3
votes
3answers
103 views

reliable scripting way of obtaining UUID of boot partition

I want to script a somewhat automated method for editing /etc/default/grub and appending fips=1 boot=UUID=???? to GRUB_CMDLINE_LINUX= coincidentally /etc/fstab contains UUID=12345blabla /boot xfs ...
2
votes
0answers
45 views

Using killall with -u and -o options

I wanted to confirm some details with the killall -o option. I tested it on some ssh connections I created under the user rick. First I printed a list of all of ricks ssh connections along with the ...
0
votes
1answer
216 views

difference between echo ($x) and a=“($x)”; echo $a

When I execute the following in terminal: x=1 a=($x) echo $a #output: 1 echo ($x) #output: -bash: syntax error near unexpected token `$x' Why are above outputs different? Also why are the ...
0
votes
1answer
42 views

Sending email via mutt as root on RaspberryPi

I have an application that needs to run as root for access to hardware on the Raspberry Pi. In this application I need to send emails with attachments containing data. I am able to write a bash ...
7
votes
2answers
116 views

Inverting an associative array

Let's say I have an associative array in bash, declare -A hash hash=( ["foo"]=aa ["bar"]=bb ["baz"]=aa ["quux"]=bb ["wibble"]=cc ["wobble"]=aa ) where both keys and values ...
-5
votes
2answers
75 views

Bash - How to find the longest txt file in a folder? [closed]

I need to write a script which finds the longest txt file in a folder. I literally have no idea how to do it
-2
votes
2answers
173 views

how to remove all characters after and including “?” in filename?

I have a large amount of files that were downloaded and ended up having what looks like authentication parameters added to the filename which I would like to remove. Examples: file1.doc?...
1
vote
1answer
39 views

turn awk command into an awk script (multiple F)

I have a working command awk -F '[)#/(:]' 'BEGIN { fw="";dev=""} {if ($0~/sh failover/) fw=$1 ; if (($0~/This host/)||($0~/Other host/)) dev=$2; if ($0~/\)\:/) {print $2,$1,fw, dev} }' OFS="|" ...
2
votes
2answers
75 views

Killing a process and diffing its result

I've been trying to write a simple bash script, but I cannot get it to work. I want to: Start a program, feeding it input from a text file (./prog < input1.txt) Wait a short amount of time and ...
1
vote
1answer
43 views

Shutdown PC after remmina connection closed

I'd like my PC to shutdown straight after I close my remmina remote connection. I searched for solutions but remmina itself shows abnormal behavior. someprogram && sudo shutdown -h 0 Running ...
1
vote
1answer
60 views

Taking input in a script and making sure there's only one parameter

I'm currently working on an assignment where I have a script that is basically just getting to learn using grep with different regex's. I have the script written except for the first part where I am ...
2
votes
2answers
1k views

Passing arguments from one script to another

Let's say I am in a Bash script and am sourcing a file. How do I pass variables to another script after I source the file like this. sed -i 's/ = /=/' $file source $file Let's say file contains ...
1
vote
1answer
81 views

Parted partition drive with small partition at the end

I would like to partition a drive from a script, so that there is a big partition filling most of the drive, then a small one at the end. So far I have come up with. parted -s -- /dev/sda mklabel ...
0
votes
0answers
29 views

Avoid using temp files for pr

I am tailing two files at the same time, side by side, I can't get a version to work that doesn't use temporary files F1.tmp and F2.tmp. I would like to use watch to call this script. Pretty sure I ...
0
votes
1answer
677 views

Linux Shell - How to remove escape characters generated by JQ when json is read with sed?

I am trying to read a json file and use its output in jq to build another json, combining so said json file and other values, and pass it to CURL I read the file with policies=$( sed 's/\\//g' ...
2
votes
2answers
453 views

Why am I getting “Directory not empty” with “rm -rf”?

I'm using macOS with rm tool from GNU coreutils (not macOS’s own rm). So I have a script where I clean up some directory like this: if [ -d "${cleanup_repo_clone_root}" ]; then echo "Cleaning up ...
1
vote
1answer
95 views

How to prevent printing to stdout from an awk **script** (not from cli)

[GNU awk v4.2.1 on Archlinux] Suppressing awk's default print action to stdout from cli is easy and well documented on UL, e.g. here. Doing so from a script gives me headaches. Here's the toy script: ...
2
votes
2answers
67 views

How to know, what SHELL is used when running a script? [duplicate]

How can I output that what shell is used to execute a script? Ex.: the $SHELL variable gives that what is the default shell for the given user. That is ok, but the given user can launch the script ...
0
votes
1answer
14 views

Counting instances in a variable, then reformatting rows/columns within bash script

Within a Batch submission script I have a file generated called "nodefile.123" that looks like: bear-pg0208u33b bear-pg0208u33b bear-pg0208u33b bear-pg0210u19a bear-pg0210u19a ...
0
votes
0answers
12 views

How to detect when NetworkManager loses Wi-Fi connection?

What is the best approach to monitor NetworkManger connections and detect when the Wi-Fi connection has dropped? My goal is to attempt reconnecting after a certain number amount of time disconnected, ...
-2
votes
1answer
88 views

grep routing table & execute command

I'm trying to make a script on my Linux machine that will grep for a specific routing in my routing table and execute command depends on the find. This is what I have so far and it's not working: #!/...
0
votes
2answers
121 views

How to timeout a program with a potentially infinite loop

Suppose I run a program that I suspect to contain an infinite loop, or some other code that might run for too long. I know that in Linux I can do: timeout 1 ./program to give the program a time-out ...
0
votes
1answer
235 views

Can't connect wpa_supplicant to wifi. SSID is not found even though it is listed in scan results

I'm using a script to add a network to my wpa_supplicant.conf and reload wpa_supplicant to connect a new network. Something like this: cat << EOF >> /etc/wpa_supplicant/wpa_supplicant....
1
vote
2answers
408 views

Bash environment variables in non interactive mode

I'm trying to define environment variable for non-interactive console in Raspbian. In theory I need to add the varaibles to ~/.bashrc or ~/.profile or /etc/bash.bashrc or /etc/profile. For example I ...
0
votes
1answer
59 views

Bash Script Case statement (if-not logic)

I wrote a small bash script. It will try to find the word ERROR. If found the resulting value will be non-zero numeric (for example 25. I mentioned in the script but it is variable numeric value), and ...
0
votes
1answer
30 views

Bash script to link networked account directories to local account directories

I'm working on a script that will create a local user account, and link local account directories to networked account directories. The only directories I would like to be created and linked are the ...
1
vote
1answer
178 views

How to parse openssl certificate output into hostname and verification codes?

I have this shell code that reads lines of host names from input file, performs an openssl command to print ssl certificate info, and outputs the results in the terminal. while read x; do echo $x; ...
1
vote
3answers
54 views

Extracting text from a file when I know its format

I am running a script which will output a file called scServer.scs which looks something like this: 49138@bber0501u29b.bb2.cluster 2 Solution 1 Fluid Flow (Fluent) Solution ...
-3
votes
3answers
817 views

script to translate xml to json

I have 5000 questions in txt file like this: <quiz> <que>The question her</que> <ca>text</ca> <ia>text</ia> <ia>text<...
1
vote
2answers
292 views

What is Linux exit status and list of all status

I'm trying to learn Linux bash scripting and I'm read through the articles in the http://tldp.org sites I saw some kind log clearing scripting I notice that something is used for as an exit status. I ...