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
0
votes
1answer
20 views

How to Search XML Block and Delete the same

This is my XML. <configGroup> <type>SERVER_CONFIG</type> <configProperty id="Server48"> <configProperty> <name>Server Name</name> <...
0
votes
3answers
38 views

Renaming files by removing delimited substring

I have a lot of folders and subfolders with files with name 1. Introduction--- [ FreeCourseWeb.com ] ---.mp4 I want to rename all files recursively (folders and subfolders) to just 1. Introduction.mp4 ...
0
votes
1answer
19 views

Bash script for monitor the API json response

I want to monitor the below health check URL. I need generate a alert if mongodb goes to disconnected state. I wrote a bash script. Seems its still not working. Any can help on this ? Thanks When do ...
0
votes
2answers
35 views

Bash scripting loop concatenate pipes / redirections based from names variable

I have a command that produces a number of output lines that I later grep searching for. Based on a past answer I know I can use a single long command and do all my filters concurrently: https://...
1
vote
3answers
24 views

Shell script, get/extract mac address from console output of command after “MAC: ”

I'm trying to automatically pull out the mac address of a arduino device using a shell script, and need some help how to do this. This is the output returned by the command: Opening /dev/cu....
0
votes
2answers
34 views

Bashrc function case statement to import cases from JSON

I'm making a .bashrc function to get me around the system faster. I used a case statement to state where I want to go. function da() { case "$1" in home) cd ~ ;; eolas) cd /...
0
votes
0answers
7 views

Netconf notification on a particular session in python

Im writing a python script to send the netconf notification to a netconf client but netconf client is expecting the notification on a particular session. The and create-subscription request are ...
-2
votes
4answers
46 views

shell: map columns of a TSV file using a separately defined mapping

Suppose I have the following tab-separated file data.tsv: 1 a 3 2 b 2 3 a 10 2 c 2 2 a 8 Now, I want to exchange the values in column 1 - say, turn them from IDs to names - by using the following ...
0
votes
2answers
70 views

a really complicated loop. Can someone help me?

I must execute a command several times changing from time to time the two files of input. I think that i have to run a loop, probably a "for" but I don't know how. The command is the following: "......
0
votes
0answers
20 views

Script to monitor log file for when something does not happen

I’m new to this scripting thing and need some insight on a script I need to write. The script needs to monitor a server’s auth.log file. Where I work, we have a setup we call a conveyor. We have ...
2
votes
1answer
39 views

How do I send output to both log file and console?

I used to put this on top of all my scripts, with regards to the output. The stopping and starting of the docker works as expected, and the log files contain what it should but the console does not ...
0
votes
3answers
54 views

Run a command if stdin is empty

I'd like to do the reverse of xargs --no-run-if-empty, so that it ONLY runs if the stdin is empty. Example use: ip a | fgrep "inet " | grep -ve " tun" -e " lo" # pipe it into something and echo ...
-1
votes
0answers
49 views

How to find login info using awk command in bash scripting?

I'm trying to write a Bash script that takes a list of login names on a computer system as command line arguments, and displays these login names and full names of the users who own these logins (as ...
0
votes
1answer
24 views

How to open ports to test nmap script?

I need to test my nmap script, which crashes when many ports are open. So I need a script (python/bash) that opens n ports on a server. How could I do that? Thank you
1
vote
1answer
42 views

Is an expansion like this possible in Bash?

I want to do something similar to this: apt install emacs-(ivy, emms, magit) ---> apt install emacs-ivy emacs-emms emacs-magit Is this possible to do with bash?
0
votes
0answers
28 views

Bash inconsistent behavior between echo / assigning a variable with `set -e` and subshell

#!/usr/bin/env bash set -euxo pipefail echo $(echo "$THIS_VAR_DOES_NOT_EXIST" | cat) echo "WTF" Running this script produces: ./wtf.sh ++ cat ./wtf.sh: line 4: THIS_VAR_DOES_NOT_EXIST: unbound ...
0
votes
1answer
51 views

Ways for making a Scala script standalone in Linux?

Programming Scala says: Invoking scripts with scala is tedious when you use these scripts frequently. On Windows and Unix-like systems, you can create standalone Scala scripts that don’t ...
0
votes
1answer
38 views

Bash script that runs parallel threads slows down substantially over several hours

I have a script I came up that simply executes another process into the background that attempts to control the max number of processes running (300 in this case). It initially executes scripts at ...
1
vote
2answers
62 views

How do I replace text that's in a specific location of a file with text located in another file with a bash script?

So let's say I have a text file, filetobechanged.txt: 3.141592 pi 6.626068 planck # Like this and like that and like this ..1 kd6-officer kd6-officer us..0 kd6-3.7 us00..0 kd6-3.8 ...
2
votes
0answers
20 views

Shutdown from a script executed by cron as root

Background I'm trying to write a script (see end of the question) that checks the temperature on Raspberry PI and shuts it down automatically if it goes too high. The script would be run by cron, ...
3
votes
3answers
85 views

Bash consecutive and parallel loops/commands

I want to run some simulations using a Python tool that I had made. The catch is that I would have to call it multiple times with different parameters/arguments and everything. For now, I am using ...
1
vote
3answers
107 views

Multiple commands and subshell execution after pipeline

Ok, I know that in Bash (by default, without 'lastpipe' bash option enabled) every variable assigned after a pipeline is, indeed, executed in a subshell and the variable itself dies after subshell ...
0
votes
3answers
33 views

bash line interpreting process

I would like to understand the exact process of line interpretation executed by bash. from GNU bash reference manual: When a simple command is executed, the shell performs the following expansions, ...
2
votes
1answer
120 views

Script that validates 3 inputs

This is what I have. I am trying to validate 3 inputs. The first and the second inputs do not ask me to enter the correct input. What is wrong? #!/bin/bash ...
1
vote
3answers
113 views

shell script to check availability of a file for 1 hour , after one hour if file not there , it will echo “Time Out”

i wrote this code. but the problem is after every 300s it prints "Time over", when $fname present is got out from the loop. I want "time over" after 1hr if file not arrived, but after 300s it starts ...
0
votes
2answers
41 views

Behavior of variable creation inside bash function

I am using the function below to increment an outside script. The main purpose of this is just to return some data from ifconfig and ping test outputs. I am trying to set them inside the same function ...
-2
votes
1answer
41 views

I cannot change directory in script using variables

My script: #!/bin/sh _directory1="/home/user/test1" _directory2="test2" cd "${_directory1}/$_directory2" for i in * do echo "$i" done And here is the error: ./myscript.sh: 6: cd: can't cd to ...
-1
votes
3answers
41 views

Print out IP address script [closed]

I need to make a script that gets my public IP address from a website and prints it out. #!/bin/bash wget http://www.ipchicken.com/ grep I don't know where to go from here. Please help
0
votes
2answers
51 views

test: too many arguments returns

I saw other posts the same problem, but I can't figure out since everyone does different things. I'm new to shell script as well, so my limited knowledge is getting more confused when I read those ...
0
votes
2answers
23 views

Error when running script involving machine name and local network

I'm trying to write a script that takes a machine name as a command line argument and displays a message informing me whether the host is on the local network. Here's what I have: #!/bin/bash ...
0
votes
1answer
27 views

How to change the background colour based on a condition of a column in Unix

I have a file with below content: <tr><td>CLNK </td><td>TR-HEH-JFGHG-MTG-N-US-00 </td><td> 841115061</td><td> 9965 <tr><td>CLNM </td>&...
0
votes
1answer
72 views

Bash script to sort files into alphabetical folders

I try to organize my files and my folders by a script. It creates the folder with the first letter of my file and moves it there. For the very first time, the script does the job, but if I create new ...
-1
votes
1answer
47 views

Loop Fails if file in list does not exist; how to handle this error

I have script that runs on server reboot, to loop through the applications under a directory and start them after a reboot is complete. Recently, I've made a refactor where it looks though a text ...
0
votes
3answers
40 views

How do I search for a list of strings with find and grep

I am trying to make the following into a bash script: #!/bin/bash find /path/to/file -type f -name "*.html" -exec grep -l "XXXX" '{}' \; -print where XXXX is a list of strings over which this ...
0
votes
2answers
36 views

Should this be two separate lines?: `. echo “test” set dat = $dcmdir/$s/scan.log`

I'm looking at a tcsh script in which one of the lines is: . echo "found scan.log, finding mprages" set dat = $dcmdir/$s/scan.log That's all on one line. Is it feasible that this is actually valid, ...
1
vote
1answer
54 views

How to execute a script based on the output of a command

I am trying to set up a cron job that will keep alive a process that is running on a particular port in a centos server. I will be able to get process id using the following command: lsof -i tcp:9090|...
0
votes
2answers
40 views

Add JSON objects to array using jq

My goal is to output a JSON object using jq on the output of a find command in bash. It could either be a one-line command or a bash script. I have this command which creates JSON objects from each ...
1
vote
3answers
32 views

How to ignore file in a for loop

I'm making a script to start up a number of services at server reboot. To do this, I'm looping over the directory, checking that each has a start.sh script, and calling that script if they do. ...
0
votes
3answers
35 views

Conflicting input and pipe variables inside a shell script

I have the following script: #!/bin/bash cat $1.txt | awk "{cmd=\"pwgen 10 1\"; cmd | getline pass; print substr($0, 1, length($0) -1) \">> ~/dresses/whole-dresses-shape/$1-\" pass \".jpg\"; ...
-1
votes
2answers
33 views

Changing permission on multiple files within bash

I am trying to write a script to change the permissions of a number of other scripts, in multiple locations, to be executable. I've searched all over and can't seem to get the syntax correct. It is ...
1
vote
2answers
56 views

Create a file with the information about line position of multiple lines

I have a file with the following column: GEOM_190_190 GEOM_190_192 GEOM_190_194 GEOM_190_196 ... Its length is around 3000 lines. I would like to write a script that creates a file with ...
0
votes
2answers
60 views

Remove argument from $@ if it is an option

I have a script where I need to loop through the arguments passed, and if an argument starts with - I need to put it in a string opts and remove it from $@. This is what I have so far opts="" for arg ...
6
votes
2answers
462 views

Is possible to define a bash script to run interactively by default?

I have written some scripts and stored them in my ~/bin folder. I'm already able to run them just by calling their title during a shell session. However, they aren't running interactively (I mean, my ~...
0
votes
1answer
48 views

makefile syntax error for if-else construct

Hi I am stuck in this problem for long time. I expect output "ok" for this makefile. But I get syntax error on calling make: ifeq (0, 0) /bin/sh: 1: Syntax error: word unexpected (expecting ")"...
0
votes
1answer
27 views

Crontab or Init.d for startup scripts in linux?

Sorry if I am just dumb about this but I am currently trying to set up my raspberry pi to start a script at startup but I cant seem to figure out which is better to use, Crontab or init.d . I can't ...
0
votes
2answers
62 views

Edit script to email output?

I'm basically trying to put two scripts I found online together. The first, in two parts, checks if a directory exists, if not creates it then goes on to take a picture through the webcam if an ...
-1
votes
3answers
55 views

Get a part of a folder name as variable

I have 2 folders names that have 2 ids like "ABFD00" and "KASD02". Now I need a little part of the folder as a variable (00 and 02) to use it in a command. Like: sapcontrol -nr $sid -function ...
0
votes
0answers
8 views

Get SAP System Instance IDs with bash script

is there a option/command to find the instance ids. I woud like to use them in sapcontrol -nr $sid -function GetSystemInstanceList sapcontrol -nr $sid2 -function GetSystemInstanceList.
0
votes
1answer
44 views

AWK script to launch a process as loop for several txt files

I have plenty of files. I need a script that iterates each file and prints columns 2 and 3 and G as first column in another file. The input files are named as UH001 UH002, UH003,...,UH123 and the ...
0
votes
3answers
29 views

I wish to replace a string containing a pattern using sed

I have the following lines in a file named ref.list. 234 ./XYZ_SiteMetric_TIMESTAMP.dat 456 ./XYZ_Site_TIMESTAMP.dat I need to make them: 234 SiteMetric 456 Site I am using ...

1
2 3 4 5
72