Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).

learn more… | top users | synonyms (2)

11
votes
3answers
165 views

Understand “IFS= read -r line”?

I obviously understand that one can add value to internal field separator variable. For example: $ IFS=blah $ echo "$IFS" blah $ I also understand that read -r line will save data from stdin to ...
2
votes
3answers
37 views

Truncating the precision of a date

I'm working with a bash script which polls build progress from several different systems. If a build is complete, it stats a log file to find out the last time it was edited, then feeds that time into ...
0
votes
1answer
130 views

systemd Failed at step EXEC spawning /opt/autologger/placeholder.sh: Permission denied

This is a really simple question, I know, but I am jumping right into systemd with little prior knowledge of system management and Linux in general. I am attempting to create a "Hello World" service, ...
0
votes
2answers
64 views

expect: does “” (spawn_id exp70) match glob pattern

I have written an expect script that works perfect for testing passwords on our network until it has looped through my list quite a bit, then the debug output shows that there is nothing to match. ...
2
votes
3answers
98 views

Format column-based text file into tree structure using bash

Is there a Unix/Linux command that can turn this: AMERICA USA NEW_YORK AB-100 AMERICA USA NEW_YORK VF-200 AMERICA USA NEW_YORK XY-243 AMERICA USA LOS_ANGELES UH-198 AMERICA CANADA TORONTO ...
0
votes
1answer
38 views

bash script failing to use ssh -i. Can't see directory

I am experiencing something strange. I am working on a script to remote install Splunk on servers via a script. In this script I ssh to my practice servers (5 amazon EC2 instances running Redhat). ...
0
votes
1answer
42 views

Supervisor: no such file or directory even though it is there [duplicate]

I am trying to start supervisor service supervisor start, as root, but it gives me env: /etc/init.d/supervisor: No such file or directory Yet, I can clearly see that file exists: ...
0
votes
2answers
54 views

while read loop

I have a file like one below var 3 2014 string var1 4 2011 string4 var2 6 1999 string2 var3 1 2016 string6 Then i have this while read loop to compare one of the ...
2
votes
2answers
61 views

How do i run a command only after previous command is unsuccessful in bash? [duplicate]

We use && operator to run a command after previous one finishes. update-system-configuration && restart-service but how do I run a command only if previous command is unsuccessful ? ...
3
votes
2answers
89 views

shell script to extract between characters

I would like to extract a user name from the file between the keywords "/" and "NET" like below. How can I do so with programs like awk, sed or cut. from: audit: command=true ...
0
votes
1answer
113 views

predetermine script input text

I have a script that automatically sets up an emailing server based off what I enter for the following echo "Please enter your main domain: (Ex.: website.com)" read DOMINIO if [ $DOMINIO = "" ]; then ...
2
votes
7answers
186 views

Restart firewall from bash file

I need to restart firewall periodically, so I created a bash file to add it to CRON tables. In terminal, I restart firewall using command: service firewall restart but if I have similar line in ...
1
vote
1answer
40 views

How to put “rm -i” in an iteration?

echo "$MOUNTPOINTLIST" | while read onelinefortouch; do touch "${onelinefortouch}testfileforwrite"; done echo "$MOUNTPOINTLIST" | while read onelineforrm; do rm -i "${onelineforrm}testfileforwrite"; ...
-1
votes
1answer
132 views

How create calculator in linux script?

I am trying to create a calculator: echo "What is your number?" read n1 echo "what is your second number?" read n2 echo "what do you want to do?" echo "1. add" echo "2. subtract" echo "3. divide" ...
1
vote
4answers
77 views

Remove all brackets in filename

I've been trying to remove all brackets in my filename(s). Can anyone help me create a bash script to do that? This bash script below work flawlessly for non-bracket filename(s), but if there are any ...
2
votes
2answers
40 views

One-liner to sort and uniq two outputs

I'm currently doing this to sort and uniq the output of two different commands: tshark -r sample.pcap -T fields -e eth.src -e ip.src > hello tshark -r sample.pcap -T fields -e eth.dst -e ip.dst ...
2
votes
0answers
74 views

Java program not working after cd in symlinked shell script [closed]

I downloaded a program, and it came with a shell script to execute it since it was written in Java. I made a symlink to the shell script on my desktop. Then I edited the script (in its real location), ...
0
votes
1answer
19 views

How to redirect the time a task takes to complete into a log file, given that such task is already redirecting?

I have a shell script running a python task, whose stdout is being redirected to a log file: python script.py >> log.txt I wish to also log the time this task takes to complete, into the same ...
-2
votes
4answers
63 views

How to print last few contents in a line?

I have a file that has lines shown below, ta=/*92/*39/*1/*649/*12 ta=/*92/*12/*4/*342/*90 ta=/*92/*33/*9/*455/*3 ta=/*92/*12/*3/*649/*25 ta=/*92/*99/*7/*649/*7 and so on. I want a file that will ...
0
votes
2answers
94 views

How do I add ASCII art to my Bash?

I see other people doing this, occasionally. They'll add something like the following to the start of their terminal, sort of a welcome screen: ____ _____ _ _ _____ __ __ _ _ __ ...
0
votes
1answer
26 views

Should I move my custom commands from the end of ~/.profile to the end of ~/.zprofile when I install zsh and oh-my-zsh?

I am a new user of zsh and oh-my-zsh. Before I installed zsh and oh-my-zsh I configured my ~/.profile to start some programs automatically. For example, my ~/.profile would start guake after a 4 ...
0
votes
0answers
38 views

CSH: Determine index number of string in an array

I am using csh. Consider an array of arbitrary length: set array = ( abc def ghi ) I have the following variable set var = "def" How can I find $var in $array and determine its index value? I ...
3
votes
5answers
148 views

View a file in a tar archive without extracting it

I want to view the content of the tarred file without extracting it, Scenario: I have a.tar and inside there is a file called ./x/y.txt. I want to view the content of y.txt without actually ...
0
votes
3answers
71 views

backup script to copy files by its extension

I have created script to copy .png files from one directory to another. Script is as follows: i="`cat /usr/local/app1/default.conf | grep -i values | sed -e 's/\values=//g' -e 's/,/ /g'`" for data ...
0
votes
1answer
125 views

Create directory and files from csv file

I have a CSV file which contains the data in the following format web_url.csv drive,http://www.drive.google.com/ wikipedia,https://en.wikipedia.org/wiki/%s ...
3
votes
2answers
87 views

Check if conditional with awk for matches in logfile

I want to check the auth.log file for accepted sshd connections and execute an action if any are found. Here is my code: tail -f /var/log/auth.log | awk '{ if($0 ~ /sshd/ && $0 ~ /Accepted/) ...
-1
votes
4answers
53 views

accessing loop variable in a loop [duplicate]

This is my script: load_1=15231 load_2=20547 load_3=24561 load_4=22874 f4=434 sum_1=`expr $load_1 + $f4` sum_2=`expr $load_2 + $f4` sum_3=`expr $load_3 + $f4` sum_4=`expr $load_4 + $f4` ...
2
votes
3answers
246 views

Using sed command to find the first occurrence of the pattern and append

Say there is a text file as below: Hello world types="" Mario types="Game" All I want to do is find the first occurrence of type="" and append with word program My desired output: Hello world ...
0
votes
1answer
31 views

How can I loggin from VM1 to VM2 using script?

I am using script to loggin my VM2 from VM1 (Password of the VM2: fifa): for i in {a..z}{a..z}{a..z}{a..z} do # $i as a password ssh root@ipaddress read i echo $i done bit it doesn't work. ...
5
votes
4answers
456 views

How to create loop sequence?

I am trying to create a script that will be getting one variable from user and should print a pyramid as below: * ** *** **** ***** I used this script but it shows me numbers: for i in {1..5} do ...
3
votes
2answers
58 views

Simultaneously check for empty output and successful exit status

I'd like to write the following test in an installer script1: if [ -n "`/etc/grub.d/30_os-prober`" ]; then install_dual_boot else install_linux_only fi However, it's also possible that ...
5
votes
5answers
284 views

How to use output redirection dynamically?

I'm trying to add a debug option to a script of mine. Normally I want to hide any output, like warnings etc, so I put >/dev/null 2>&1 behind a lot of commands. Now, when I want to debug my ...
-2
votes
3answers
76 views

Removing column in field seperated file using scripting

The files is seperated by | pipe symbol myfile.txt Hello|how|are|you|hope|you|are|doing|fine Lilly|jasmine|rose|sunflower|nightfire|flowers I want to remove columns greater than 3. I want result ...
4
votes
2answers
101 views

Copy the files automatically to destination as soon as created

Is there any way to copy the file in Unix as soon as it is created? I have one location where files will be created in different timings.How can I copy the files automatically using shell script to ...
1
vote
2answers
68 views

How to add all values in an array

I have been stuck on this for way to long now. Tried googling and couldn't find what I was looking for. I simply need to add all the values in an array.(array called packets) I have gotten to the ...
2
votes
1answer
51 views

Capture specific column from command output

I know how to redirect first 5 lines of the output to a file when I execute a command. I want to know how to redirect only specific information from the output. For example I would like to execute ...
0
votes
2answers
70 views

Shell Script: Use “find” to execute shell a command that contains “filename”(without extension) returned from “find”

I have several files with extensions "*.f90" in directory-A. I want to apply the following command for each file in shell script. e.g. filename.f90 f2py -h filename.pyf -m filename ...
11
votes
2answers
180 views

Correct behavior of EXIT and ERR traps when using `set -eu`

I'm observing some weird behavior when using set -e (errexit), set -u (nounset) along with ERR and EXIT traps. They seem related, so putting them into one question seems reasonably. 1) set -u does ...
3
votes
4answers
60 views

How can I make source-highlight colorize .dotfiles by default?

Normally when I cat a file like this it's hard to read without colorizing. I've managed to get cat to use source-highlight like this: cdc() { for fn in "$@"; do source-highlight ...
3
votes
1answer
103 views

Find, count and sort all audio files. ALAC (M4A) files

I'm putting a script together to sort a very large music collection. It's approx 22000 albums, a mixture of FLAC, WAV, AIFF, M4A (AAC & ALAC). So far, I can sort by file type and get a total size ...
3
votes
4answers
271 views

How to use sed command to modify a file's entry line by line in shell script?

This is my file1: #$BQ #{ VOL @home } #database daba #relation tcdeatid #copy 1 #{ version 0 } #opendb #clear #.lruno := 72 #.infno := 1 #.tid.noel := 101 #.tid.info ...
1
vote
1answer
57 views

Why does my bashscript not work?

So I made a bash script to automatically get ts3 installed and running on my vps, but for some reason it doesn't work. The error I get is: > /root/install/ts3install.sh: 4: cd: can't cd to ...
5
votes
1answer
56 views

How to stop a background process started in the same script, without exit the script?

I have a program that takes a variable time to run (no more than two minutes), and to make it less odious, I put fortune messages. #!/bin/bash ... for i in $(seq 1 45); do sleep 3; echo; echo; ...
0
votes
3answers
53 views

Extract value from one file and insert it into another file replacing some other value

I have two files, whose line numbers are not same. But in file1 I want to replace lines taking reference from file2 using sed command. In file1: tid.infno := 72 tid.setnr := 120 (This number 120 is ...
0
votes
2answers
93 views

shell scripting export file

I have output that I need to export to a file. Then I need to call this file to run the script in it. Another condition would be to run the last query or instruction after 15mins. See code below: ...
0
votes
1answer
77 views

Php shell_exec() : for non root user, how to access root command

I have a tricky step to walk for my system (openvpn, 20 clients - raspberries, 1 server CentOS). I want to make an auto install, from clients, for their keys. They call a php page on the server, ...
0
votes
0answers
81 views

(noob) script works from root ssh <-> php shell_exec() does not

A nooby2death question: In a vpn project, I generate keys automatically for clients. I do this with a script file containing : pkitool clientNameForKey This line : - does work if I execute the ...
0
votes
2answers
42 views

How to check option is set to bash script? [duplicate]

I'm creating a basic bash script which deploy a simple webapp. My current code is as follows. #!/bin/bash clear echo "********************************************"; echo "Hello, I'm going to deploy ...
1
vote
1answer
154 views

How to use afl-fuzz (American Fuzzy Lop) with openssl

I am trying to use afl-fuzz with openssl in Ubuntu. A normal usage of afl-fuzz would be: afl-gcc test.c //-- this will produce a.out mkdir testcases echo "Test case here." > testcases/case1 ...
2
votes
2answers
78 views

Getting Group Names for List of Users

I have a text files with a list of users formatted like: name1 name2 name3 ... Calling the command groups gives the primary group name for that user. ex: bash$ groups name1 name1: ...