Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-1
votes
0answers
9 views

How do I run a .sh script already on the remote server through telnet from a different computer

I need to do the following: 1. There are two linux-based servers, server-1 and server-2. 2. The only way to access server-2 is by logging into server-1 and using ftp to transfer files etc. to server-...
0
votes
0answers
23 views

Comparing all combinations of lines within two columns using awk + if statement

I have a file with 11 Columns of data deliminated by a space between each. For each line in column 2, I need to find the closest value in column 9. So below it would take the first entry in column 2 (...
1
vote
0answers
23 views

How to capture all std outputs [duplicate]

Suppose I have a program called mktemp which creates a random tmp directory in /tmp and also produces a string output of the directory address Input[0]: mktemp Output[0]: /tmp/tmp.MkrKAscwwk How can ...
0
votes
0answers
23 views

Shell script to execute other script not spawning other scripts

I have a shell script running in a while loop. The script accepts a number as an argument so in ps you would see something like /path/to/script.sh 2. Every 180 seconds, it should be spawning a PHP ...
0
votes
0answers
24 views

change date format in the following script [on hold]

The following script will take the system date in the following format dd/mm/yy string(today,"99/99/99") + I want it to change to mm/dd/yy. Please let me know how to achieve that.
0
votes
1answer
63 views

How to print / echo positional parameters index

I have this working and simple code to echo positional parameters VALUES for i do echo "Argument = $i " done Here is the actual output from the scrip Argument = --atleast-pkgconfig-version Argument ...
0
votes
3answers
28 views

remove specific characters from a string

I need to replace spaces with comma and then remove certain extra specific chars from a string. echo "$d" >>Mon Apr 22 05:06:00 UTC 2019 jent=$(echo $jt1 | sed 's/[[:space:]]/,/g') echo "$jent" ...
-1
votes
0answers
23 views

How can I check if a file is available on SFTP?

I'm writing a script where it should connect the remote host and then, connects to sftp and list the current day file I got to a certain point with what i wrote: #!/bin/bash key="keys/prod_key" date=...
0
votes
0answers
22 views

How to run 2000 processes with chroot

I have a program that needs to be run in about 1000 instances, each in a different independent directory (/mnt/x_1, /mnt/x_2... /mnt/x_1000). What I'm currently doing is mounting /bin /dev and /etc in ...
0
votes
1answer
31 views

Why my script is not working? [duplicate]

Hello I am trying to move a group of directories with the mv command and curly braces expansion as follows: #!/bin/bash ... group_name=$1 group=$((total/set)) group=$((group-1)) mkdir "$group_name""...
3
votes
2answers
37 views

How to temporarily disable sudo credentials timestamp timeout?

Let's say, I have the following bash script: #!/bin/bash sudo command1 command2 sudo command3 I don't want to run command2 as root, so I won't run the script itself with sudo. Therefore, as soon as ...
1
vote
1answer
42 views

Confused about determining if a shell script is running interactively

I only want to determine from my POSIX shell script, if it is running interactively, but for some reason, the following function: running_interactively() { printf '%s' ${-} | grep -F i > /dev/...
0
votes
0answers
23 views

How to set variables in nested ssh session

I want to set some variable in ssh session which is nested. ssh host1 << EOF ssh host2 << EOF1 myvar="Hello" echo=\$myvar EOF1 EOF What is wrong in this bash ...
0
votes
1answer
58 views

How to rename a file with different name?

I have a file named servername_test_LINUX_test_test_2019-04-19.xls I have to create multiple copies of this file, with the condition that server name should be changed in each file created e.g. ...
1
vote
1answer
20 views

korn shell - if a variable exists in an array stop processing without exiting

How would one evaluate priority of items in an array such that you only process the highest priority item that exists? Let me try to explain, if I had an array set -A array low medium none high ...
0
votes
3answers
63 views

Find and replace Pipe using awk command

I am trying to grep column 7th with pipe delimiter (|) data in that I have to removed pipe (|) from middle of text. Sample file: col1|col2|col3|col4|col5|col6|col7|col8|col9|col10 value1|value2|...
-1
votes
0answers
34 views

Script that checks a process's running status

I need to make a script that checks if a java jar is running on a particular port or not.If the jar is not running then the script should run it automatically. let's say I want to check if my jar xyz....
-4
votes
0answers
27 views

Linux script to move item from one folder to another

I want to write a script to read a file which contains the below information.The script needs to process each line. Folder A goes to Folder AX condition=name starts with RED Folder B goes to Folder ...
0
votes
1answer
23 views

How to automate a series of keystrokes involving two GUI applications

I have two windowed applications that I need to send a series of keystrokes to. I need to Alt-Tab back and forth between the apps, and I'd like to be able to reduce the number of keystrokes from six ...
-3
votes
1answer
43 views

Scripting School Assignment renaming files without extension .old to have .old [closed]

My goal is to change the file extension of files that do not have the .old extension to contain it after the script. Another goal is for me to do it with a for loop piped with grep -v to check match ...
1
vote
2answers
35 views

How can I read a txt file line by line and sort them by the correct variables and write them to another file?

Here is an example of my txt file John NY 2019 APR Mark SC 2019 JAN Ava CA 2018 AUG Here is the example of the target txt file Name,Location,Year,Month John, NY,2019,APR Mark, SC,2019,JAN Ava, CA,...
0
votes
1answer
25 views

Looping through all files, skipping some dynamically

rather new to unix. Trying to create a script to loop through all files and subdirectories given a directory and printing them. I would like to be able to skip certain directories dynamically though. ...
0
votes
1answer
31 views

auto enter password for `passwd <new user>` from script? [duplicate]

if the script was useradd ...............<new_user>; passwd <new_user>;. is there a way to put the new password in a script? I don't need to change or add an old password for an existing ...
0
votes
1answer
34 views

Find out if the connection to Wi-Fi was successful

I need to do some script, which find out if the connection to the Wi-Fi was successful or not. I have Wi-Fi configuration in /etc/wpa_supplicant.conf. I know how to add SSID and PSK to this file and ...
0
votes
0answers
17 views

Ubuntu 14.04 ,looking for script auto restart eth0

I got the problem on 14.04.3(default install iso, do not apply network update or upgeade to 14.04.6), the system sometimes network fail, can't ping other one and arp get the mac address show ,i need ...
0
votes
1answer
36 views

How do I increment an integer in an URL?

I want to scrape a forum by using an API and curl. API: https://api.hackertarget.com/pagelinks/?q=websitetotest.com Here is the initial link: https://bitcointalk.org/index.php?topic=840124.0 ...
-1
votes
0answers
16 views

Automating the addition of a new WordPress site on Nginx server

I want to build a script that allows me to add new WordPress sites to my nginx server. Currently, when I need to add a new site, I must manually do a few basic steps: Create an Nginx vhost config ...
1
vote
1answer
19 views

How to prevent a command from ticks from being executed in Linux bash scripting

I want to save in variable $COMMAND the second tab delimited field from variable $i, however when I do that, the command cd ~ gets executed. There is a tab character between TEST_CASE_001 and cd ~ i='...
0
votes
1answer
16 views

How to mv file created from commands to a directory

I need to move file to a directory named after a parameter. So far im stuck on how to moving file to the directory. mkdir "$3" cat /dev/urandom | tr -dc A-Za-z0-9 | head -c 255 > $(shuf -n 1 /usr/...
0
votes
0answers
25 views

Inserting column headings in awk command

I have a raw file (gx.txt) having below sample contents shown below. TIME;PCS/Main:GxCCAInitialSuccES;PCS/Main:GxCCAInitialSuccSILP;PCS/Main:GxCCATermSuccES;PCS/Main:GxCCATermSuccSILP;PCS/Main:...
1
vote
0answers
41 views

How to get the average CPU usage over the past 10 seconds in bash?

I need a command that would echo the average CPU usage over the past 10 seconds in Ubuntu 18. Each of the following conditions must be met: It must be lightweight with a very small footprint, ...
1
vote
1answer
37 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
293 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
876 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?
1
vote
1answer
40 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
24 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
44 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
31 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
64 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
249 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
41 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
26 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
106 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 ...
-1
votes
0answers
31 views

SFTP connection test

I have a file with multiple, delimited with "|". I want to extract field 3-fqdn and 4- userid (cgi) and add it to some variable. Later I want to use those variable to test the sftp connection line by ...
-2
votes
1answer
64 views

Shell script to process text into another text file [closed]

#!/bin/bash ********************************************************* #The script will create Jenkins Instance" ********************************************************* set -e if [ $# -lt 4 ]; ...
-1
votes
0answers
61 views

Compare CSV file with while read loop in bash

I have two csv file like this : File 1 : Monday,XXXXX,XXXXX,XXXXX XXXXX,XXXXX,XXXXX,Friday XXXXX,XXXXX,XXXXX,Thursday XXXXX,Wednesday,XXXXX,XXXXX File 2 : Monday,XXXXX,XXXXX,XXXXX XXXXX,XXXXX,...
3
votes
2answers
91 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
194 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
151 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. ...