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

learn more… | top users | synonyms (2)

2
votes
0answers
31 views

How to sort files by their dates into timestamped folders? [duplicate]

I want to sort about 2500 images every day into folders with a timestamp. So far I have this script but it's not working.... for x in *.jpg; do d=$(date -r "$x" +%Y-%m-%d) mkdir -p "$d" mv -- "$x" ...
0
votes
1answer
64 views

Translate Windows batch script into a bash script for Linux

I'm new to Linux and am trying to find the equivalent of this from Windows @echo off if ".%1" == "." goto TellSyntax set ...
1
vote
3answers
59 views

Simple install script says it is unable to locate package

This install script is giving me the error Unable to locate package for most of the programs. #! /bin/bash apps=( 'python-dev', 'python-pip', 'python-numpy', 'python-scipy', 'python-matplotlib', ...
1
vote
1answer
83 views

Bash: Looping through a string

I have a variable Vmac that stores values of multiple MAC addresses, collected from wmic call as follows: Vmac=`wmic --delimiter="," --authentication-file=/path/to/file //IP-ADDR "Select ...
1
vote
2answers
41 views

Some characters disappear after processing a text file

I've a file named addresses.txt : address1@domain.com address2@domain.com address3@domain.com I'd like to echo "address1@domain.com.html" using for loop. Here's what I did : cat addresses.txt | ...
1
vote
4answers
65 views

Delete all files in a directory

I have a directory which includes some files and some folders containing other files. I'm trying to remove these files in the main directory without touching the folders or their contents. I'm using ...
1
vote
0answers
21 views

cut comand in loop and row as a variable [closed]

I need to use any command in loop to cut different column for example like cut -fi file1 > file2 where i required to be as a variable (column number)
2
votes
1answer
31 views

Copy files that partially matches another files in another location

I have a list of jpeg files in a directory like this (below is just a sample, like the structure is the same but this there are many fo0# sub-folders, not only fo01 and fo01, where each of these ...
2
votes
4answers
126 views

Creating directories in a loop and moving files to those directories

Consider a directory with N files. I can list the files alphabetically sorted and store the list by ls > list Then I want to create n sub-directories in same directory, which can be done by ...
-2
votes
1answer
63 views

How to parse json output through shell / Python [closed]

I am running a curl command which gives me json response. Now I want to parse the response output to get the keys and corresponding values from the output or getting value for a particular key. I ...
1
vote
1answer
122 views

How to launch shell script with double click in CentOS 7

I need to be able to execute an executable shell script (sh) with a double click. I set the executable flag on the permissions for the file, and yet when I double click on it, it opens in a text ...
1
vote
2answers
48 views

Rename files depending on their parent directory

I have a main directory, let's say main. This main directory has some folders, among which are three folders named ccc ddd and lll, which are the only folders I want to target and work on. Each of ...
1
vote
1answer
35 views

Not getting the desired output for echo command [duplicate]

Below is my script. #!/bin/bash SERVERS="sl20rht00-t" #SERVERS="shcbrht01-t" USR="adm-dt-c" for host in $SERVERS do ssh -tt $USR@$host 'sudo cp /etc/sudoers /Backups/sudoers_11thmarch2015; sudo cp ...
0
votes
1answer
67 views

Detecting if ssh login fails

I have this line to run in a script, the issue is that I have to run the script over several hosts ( and it includes windows servers) and I don't know how to catch the error if the ssh receives ...
4
votes
2answers
90 views

Replace string in a file with another where both are saved in variables

I want to replace a string found in a file with another string, but both have a special character (in this example it is a . char) e.g 1.0 and 2.0. So this is the command currently used: sed -i ...
1
vote
1answer
35 views

Replace a string in a text file using a shell script not working properly

I have a text file containing this: 0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 1.0 1 and I want to replace the 1.0 to 2.0 so that it becomes: 0 0 -1 0 1 0 0 0 0 -1 0 0 1.5 0.0 2.0 1 so I use this ...
0
votes
2answers
40 views

Script with multiple arithmetic conditions failing

I'm experiencing problems with a script converting numbers to bytes. If the number is large enough to hit gigabytes or terabytes, the script runs as it should. If the number converts to kilobytes, ...
1
vote
1answer
20 views

VM cloning VS scripted setup/configuration

Perhaps a question of ignorance but... I have long since documented the steps required to configure my servers (Apache, NGINX, Samba, Postfix, whatever). Reproducing a server setup is simply a ...
2
votes
0answers
20 views

How to recognize a state of idleness for a given period in a script?

I would like to write a simple script, that should work as a daemon. The only thing this dameon has to do is to check if for a given period neither a key has been hit, nor a mouse moved, nor a ...
5
votes
4answers
386 views

list graphical processes from terminal

Do no confuse the question here with how to list processes graphically, that is not what I am asking. In the Terminal, how can i see which processes have a GUI? as in things like firefox, vlc, ...
0
votes
1answer
43 views

Bash/OSX script to run commands in 2 Terminal/iTerm tabs?

To run my node server proxy and then my project in Gulp Browsersync, every time i need to run node server in one tab, open a tab in the same directory and run Gulp. I'm not sure if the second tab is ...
1
vote
2answers
38 views

How do I update the dates (by 30 days) in the files going to that specific location in unix?

How do I update the dates (by 30 days) in the files going to that specific location in unix? Can awk or sed help ? File format is as below - Thomson: xyz Format: 1 Character_set: ASCII8 File_type: ...
0
votes
2answers
67 views

Regular expression for excluding data within a certain range

I want to remove all the IP addresses which are of the format 10.20.30.* and whose last 3 digits fall in the range 0 to 200 and move all the remaining IPs to a new file. I've put the IP list to be ...
-1
votes
1answer
45 views

permission denied on running script despite +x

Script is on exec partition (under /home/~~~ ) and have +x flag (-rwxr-xr-x ). executable on bash shell (not with script) but not on script. script is quite simple. #!/bin/bash data=cat ...
1
vote
1answer
47 views

How to pass a path to a file through a call to perl from bash?

This is a more advanced version of a previous question (How to pass arguments to perl when trying to change a line?) I made. This time I am trying to pass a path, but evertything seems that the the ...
2
votes
2answers
110 views

Script to determine if files are Images

I would like to create a shell script that will check to make sure all files in a directory are image files. We recently had an issue where a hacker was able to generate a file in a directory and ...
0
votes
1answer
30 views

how to stop at a specific point in a list

I created a shell script called blossom() because my girlfriend's dog Blossom poops and pees on the floor all the time. blossom() { echo poops and pees on floor all the time } Because I am such ...
0
votes
4answers
48 views

How to classify these lines in this ASCII file

The ASCII file I have is this: a 1 2 3 1223 b 1 2 3 5 3344 1223 c 1 2 34 a 4 5 c 123 How do I collect the lines below a,b,c respectively? Q: What would I do to get the lines below? a 1 2 3 1223 4 ...
2
votes
2answers
33 views

How to Save variables in a script that can be shared between two runs of awk against the same input file in the script? [closed]

I have a log file, whose formatting is very consistent and which I control. It produces pipe-delimited fields of constant length. Two fields are relevant to the filtering process I wish to create, ...
3
votes
3answers
151 views

Splitting a sequence into fixed width

I have a file like this which is a two-column tab-separated file. CTGCAGTTTCCCCAAATGTGGGAAACTTGACTGTATAATTTGTGGCAGTGGTA a1 GATTTCCCCAAATGTGGGAAACTCACTCGGCAGGCGTTGATA a2 I want to get an output ...
0
votes
2answers
40 views

Run script and not lose access to prompt / terminal

I am running jmeter by launching the .sh script, once I do that I cannot start using the prompt again unless I ctrl-z, ctrl-c, or the script ends in some other way. How can I launch that script and ...
2
votes
2answers
70 views

Create array in bash with variables as array name

I'm not sure if this has been answered, I've looked and haven't found anything that looks like what I'm trying to do. I have a number of shell scripts that are capable of running against a ksh or ...
1
vote
1answer
70 views

Run shell script from crontab after server stop/start/restart

I want to schedule a shell script in crontab that runs whenever server restarts. It should also run when someone starts the server after it stops abruptly or crashes. How to do so in crontab? Any ...
-3
votes
1answer
68 views

Using AWK to define variables in a shell

I've got a live MQTT stream being filtered out and dumped into a CSV file. I use the fourth parameter ($4) and fifth parameter ($5) in the CSV file to locate the information I want. I give this ...
0
votes
0answers
33 views

Error while setting up environment for running swift

I am getting the following error when running the script remakerings # remakerings Traceback (most recent call last): File "/usr/local/bin/swift-ring-builder", line 5, in <module> ...
0
votes
2answers
50 views

Not getting grep with a variable

I am assigning a variable to echo command which generates a random number. For eg: n=$(echo $(( (RANDOM%6) +1)). I have to grep this variable in /etc/passwd. So, my syntax reads like: n=$(echo $(( ...
3
votes
5answers
301 views

How do I loop over output from shuf?

If I do gshuf -e $(seq 1 10) in bash it will print the numbers 1 thru 10 in random order. But if I do: a=$(shuf -e $(seq 1 10)) for i in "${a[@]}" do echo $i echo "next" done It prints ...
0
votes
0answers
19 views

How to backup current chkconfig configurations

How to backup current chkconfig configurations chkconfig --list list the current services configurations, and when (run level) a service set to start. I need to backup the configurations and check ...
0
votes
1answer
50 views

What is wrong with my init.d script [Segmentation fault]

I currently filter out data from a MQTT live stream. I then dump this datum into a csv file named mqtt.csv and the dumping process is done by executor_start_up_job.txt which is written in BASH. I ...
3
votes
3answers
45 views

How to change directory from script without calling the script with . ./script, or exit the script when calling . ./script.sh

I have a bash script which moves the user calling the script to new working directory. If I call the script with . ./script.sh cd works, and user gets moved to new directory, but the problem is that ...
0
votes
2answers
77 views

linux curl POST request not working

I am trying to make a POST request using curl to retrieve exam results from the page : result odd .... I am using the following syntax but various errors are showing up (like content has moved ...
0
votes
0answers
69 views

'cp:cannot access file' error in script?

This is the code: #!/bin/bash $REPORT_PATH='/data/operational/logs' cp "$(`ls -t | head -1`)" "$REPORT_PATH/new_file" This gives error 'cp:cannot access pda_param'. pda_param file is o/p of ls ...
0
votes
1answer
78 views

Shell script printing blank $USER variable when executed by Smartd

I have created a script that smartd daemon (smartmontools) executes as per command below. DEVICESCAN -a -m email -M test -M exec /usr/share/smartmontools/my-script -n stand... Smartd appears to be ...
3
votes
1answer
148 views

Bash scripting to scan files for words and create report

Ok yes this is a homework assignment BUT I am NOT looking to have the answers given to me. The scenario is that I need a script that searches all my users home directories for bad words. I need the ...
1
vote
2answers
81 views

execute a script with some permission

In myscript I have a line that does this : chmod 660 somefile_given_as_argument_to_myscript I gave the members of a group the right to exectute the script. (chmod 770 myscript) but when they ...
1
vote
1answer
51 views

How to Subscribe a Bash Script as a MQTT Client

From my understanding: Client can be any device as long as it has an MQTT library running on it, from a microcontroller to a server, but must be connected to an MQTT broker over any network Broker ...
0
votes
1answer
36 views

How to send multiple email results to my email in single message

I would like the email results to be delivered to my email in a single message. Can you please tell me how can I do it. Here is a copy of my script below. All 3 email matters should come in single ...
0
votes
1answer
17 views

I'm trying to deploy with git to a semi-managed vps, need to write a script to change owners

I'm trying to deploy my sites on my company's semi-managed vps server using this tutorial: https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps It ...
0
votes
1answer
44 views

Parse header in a file and based on the header replace a value in the file

I have a problem I need help with. I'm not very experienced with awk, but it seems to be a good tool for this job. I have the following file Field1|Field2|Field3|Field4|Field5 a|b|c|d|e 1|2|3|4|5 ...
3
votes
1answer
29 views

Pipe command output to Yad and also log the output to a logfile

Need to have the process of command typically an update to be shown using yad and at the same time log all the output to a given log file set up. This is what I have apt-get update | yad ...