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

learn more… | top users | synonyms (2)

4
votes
5answers
299 views

How to delete files from a folder which have more than 60 files in unix?

I want to put a script in cronjob which will run in a particular time and if the file count is more than 60, it will delete oldest files from that folder. Last In First Out. I have tried, ...
3
votes
1answer
58 views

Regex for crontab validation

I need to check in bash whether an entry into the crontab file is valid. Is there a crontab command switch? I can extract individual lines and try to control individual items through regex. But I ...
0
votes
0answers
14 views

How to prevent wpa_gui from minimizing to systray after closing its window

The issue with wpa_gui I have nice networking setup of wpa_supplicant roaming + dhcpcd autoconfiguring the interface, both running in the background. It works very well, but the issue is with the ...
3
votes
6answers
236 views

How to keep last exit status after test

Is it possible to keep the last command exit status ($?) unaltered after a test? E.g., I would like to do: command -p sudo ... [ $? -ne 1 ] && exit $? The last exit $? should return the ...
1
vote
1answer
56 views

echo a colored text with tabs

I have the line below to echo values with tab between them. The text is also colored, however, some\t does not work. The output of this one below will have the first two \t not working. echo ...
1
vote
2answers
41 views

shell or perl script to check group have read privileges

ls -l drwx------ 8 ws web 1024 Apr 29 2013 abc drwxr-xr-x 8 ws web 1024 Oct 19 2011 def I need some script to find directories like abc which doesn't have read/execute permissions ...
1
vote
4answers
88 views

How to insert lines from one file to another file using shell commands?

I want to write 8 lines from file1 at the beginning of file2. My file1 contains the following lines: $BQ { VOL @home } database daba relation tcdeatid copy 1 { ...
4
votes
4answers
52 views

Echoing something with multiple quotes and key characters (&, $, !, etc.)

Let's say you have to echo this into a file: RZW"a4k6[)b!^"%*X6Evf How do you do it? My actual "line" to echo is a 2048 characters line.
0
votes
4answers
68 views

Unix bash/ksh : Selection of first non space character from file from specific line

I have file file1.txt whose contents are as follows: Date List ----------- Quarter Date Year Date Month Date Now I want to read the non space elements from each row of ...
11
votes
3answers
122 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
30 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
46 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
41 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
79 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
25 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
25 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
41 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
53 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 ? ...
2
votes
2answers
63 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
61 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
170 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
38 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
125 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
58 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
34 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
68 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
15 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
56 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
61 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
0answers
22 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
27 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
108 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
58 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
65 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 ...
2
votes
2answers
73 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/) ...
0
votes
4answers
50 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
193 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
28 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
434 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
52 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
249 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
51 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
85 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
59 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
41 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
63 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 ...
10
votes
2answers
117 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
52 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
92 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
3answers
181 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 ...