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

learn more… | top users | synonyms (2)

0
votes
2answers
156 views

Debian autossh boot script not working properly

I wrote the start script at the bottom of this question to try to get one of my devices to automatically create several remote forwarded ports with my VPS upon boot. (I've stripped the LSB tags to ...
2
votes
3answers
91 views

Copy files to a destination folder only if the files already exist. but the source files have a different file extension

Copy files to a destination folder only if the files already exist. but the source files have a different file extension. i.e I have a backup of some files with ".desktop.in" extension and I want to ...
1
vote
1answer
34 views

Specify the type of field to modify in a file

I have a list of clients, "code", "name", "location", "etc" and I want to make a function that asks the employee to give the client's code and then the field he/she wants to change. For example, ...
1
vote
0answers
46 views

Text User Interface

I have been working on a shell script, and was wondering if I can put up a text user interface for the shell script. After some searching, I see few people suggest using "ncurses/curses". However the ...
1
vote
1answer
122 views

Shell script `rm -r`: Redirect write-protected prompt and answer “n”

I have a few lines in a shell script whose function is to iterate through directories, match some names, and delete them. Some areas of the file system are write protected and I would like to leave ...
2
votes
3answers
95 views

Calculate date difference between Last modified date of a file and NOW using shell script

I am trying to calculate the time elapsed since the log file was last updated. I guess following commands will be used lastUpdate=$(date -r myLogFile.log) now=$(date) How can I subtract them and ...
3
votes
5answers
183 views

Pick the latest file based upon the sequence number given in the file name

I have a requirement, I have few files in a directory, I need to pick the oldest one for processing. For Exp: I have below files in /tmp directory: Sample_0000237826-001_xyz.dat ...
1
vote
1answer
27 views

Record commands only to file

How can I record commands only to a file? I imagine something like the script command, but not recording prompts or the OS response, just the entered commands followed by a line feed. I want to ...
1
vote
1answer
117 views

loop through multiple folders and perform commands then write to file

I have 10 folders that I want to loop through while executing the following command: awk 'FNR > 1' *.csv | sort -sk 1,2 | sort -sk 3,3 > ${f}_appended.dat With a for loop wrapper, like ...
-1
votes
1answer
49 views

Can you please tell me what is wrong in below script?

script : it is giving below error. please help me. basically i need to get email when memory exceeds some limit. error : ./vamsitest.sh: line 10: [: missing `]'   #! /bin/bash # Total memory ...
0
votes
2answers
46 views

provide password for script begin called inside another script [duplicate]

I have written a shell script which in turn calls another script, but the second one prompts for password. I want to supply the password and pass the prompt without user begin notified. Here is my ...
3
votes
1answer
56 views

Edit a file via a script yet maintain the osx tags

On OSX you can have tags which allows you to identify different categories of files. Here are two text files with different tags when viewed in Finder: I have a large number of these files and have ...
1
vote
1answer
22 views

Files missing after using mv and parameter substitution in a loop

Related questions to missing files after mv don't appear to answer my question. The following commands were run within the working directory where the files are located, resulting in missing files. ...
0
votes
2answers
98 views

Gzip file but excluding some directories|files and also append current date

I'm looking for a way to create a .tar.gz file from a directory but I have some doubts. I'm know that the command for create the file is: tar -zcvf /path/to/compressed/file.tar.gz /path/to/compress ...
0
votes
0answers
46 views

single jq command with multiple output possible?

I have json log file test.log {"type":"1","fname":"AAA","lname":"bbb" } {"type":"2","state":"gujarat" } {"type":"3","city":"ahmedabad" } {"type":"3","city":"rajkot" } ...
4
votes
1answer
153 views

Can I refer to a global variable even if a locally scoped one exists with the same name?

If I have a variable x total=3 and then a function function A () { local -i total=0 } Is there any way I can update the 'global' total variable total from within function A ?
1
vote
2answers
122 views

use “read” command to pass lines as positional parameters to a shell script

The following file runs, but not doing anything, yet it does not error.... while read dates; do ./avg_hrly_all_final.sh ${dates}; done < ./dates_all.csv I have a list of dates in ...
0
votes
2answers
49 views

I want to print the value from csv file dynamically

I want to print the values from properties file dynamically I am using below code but getting wrong output. testProperty.properties edmcws,edmbws,edmwt Code ...
3
votes
3answers
726 views

spawn - command not found!

I am using Mac OS X 10.9.4, following is my script to copy files from local machine to different host #!/bin/bash #!/usr/bin/expect echo "I will fail if you give junk values!!" echo " " echo "Enter ...
4
votes
2answers
75 views

Use lines in a file to produce string and file name

I have a file, foo.txt, that has a folder name on each line: folder_1 folder_2 folder_3 And I'd like to do something like this: cat foo.txt | xargs -I {} echo 'function {}() { return stuff; }' ...
2
votes
3answers
81 views

How do I use inserted values using getopts

I have this bash code combined with getopts and if I understood getopts correctly OPTIND contains the index of the next command line option and all the command line options provided to shell script ...
2
votes
1answer
58 views

attempting to put dynamic input data in a variable via cat method

I'm attempting to write a bash script that should be able to collect data from ttyS0 and put in a variable. I need to talk with a device on the serial line, that is a module able to receive AT ...
1
vote
3answers
121 views

Traverse all subdirectories in and do something in Unix shell script

I am new to bash scripting. I am working on a shell script and got stuck from last 3 days. I want my shell script to visit all subdirectories in a main directory. Do something in directories, sent ...
1
vote
2answers
82 views

Extracting numbers with a decimal point from ls output in Bash

I would like to extract the numeric part of the file names that begin with "hsli" and end with ".h5" in Bash on Ubuntu 14.04.1 64-bit LTS. My ls -l hsli* output is as follows: -rwxrwxrwx 1 ongun ...
0
votes
1answer
16 views

how to find the files in a directory with Prefix__date_030000_1.txt?

how to find the files in a directory with Prefix__date_030000_Suffix here Prefix is the Actual file name and format of the date is date +%Y%m%d and Suffix is the '.txt' and the 030000 number will ...
0
votes
1answer
62 views

Run windows local program from remote linux

I'm trying to run a python script on a remote linux machine accessed by SSH from my local Windows machine. The script contains a loop where for all files in a directory it's going to go to a certain ...
1
vote
1answer
49 views

Handle compress command error messages on AIX

I am working on production issue and unable to reproduce error message for compress command. Current Solution We have case-esac block in shell wrapper that handles messages as follows; case "$MSG" ...
-3
votes
1answer
54 views

find all .sh files then copy to <date>scriptbackup

Locate all the .sh scripts you have created in your Linux installation (searching recursively if needed – excluding existing backup folders) It will then copy them all into a folder called ...
1
vote
1answer
156 views

Print lines between two patterns matching a condition in awk

How can I print lines between two patterns which meet a certain condition? For instance for an input file partially containing the following: Time %MEM %CPU %SWAP 00:05:02 7.3 ...
1
vote
1answer
60 views

getopts passing value of declared parameter to function

I have function port.sh as stand alone script and i'm wondering if is possible to put this function in the same script where getopts is and pass value of OPT_B into function and get output of it? ...
0
votes
2answers
51 views

How to call on 3 scripts inside a shell script

I am battling to run a shell script which has 3 scripts which it needs to call and execute one after each other as soon as the execution completes successfully (error: gzip:.gz: unexpected end of ...
0
votes
3answers
127 views

Parent script continues when child exits with non-zero exit code [closed]

I have a script that calls another script. When the child script fails, I'd like the parent to fail as well. In the child script child_1.sh, I have something like this: if [ $SOME_BAD_CONDITION ] ; ...
0
votes
2answers
168 views

Read line from a file

Hello how can i read each line from a file and compare it with other file... Actually that file should be taken from command line.... please help me out if [[-f $@ ]]; then for "$line" in $@; ...
4
votes
2answers
311 views

Delete files older than specific file

I need to delete from a folder all files older than a specific file. Running bash on CentOS 7. I have a solution for this, but I think there should be a more elegant way do it: ...
1
vote
2answers
71 views

print the output of 2 commands in 1 file on the same line

Thanks for looking at this. I have a possible simple question, but I wasn't able to find any help so far on the internet. I have a script that has mainly 2 commands that process output. But both ...
1
vote
2answers
81 views

Search for matching files with wildcards without using find in a bash script

For an assignment, I'm supposed to write a bash script that can act as a very basic find, but without actually using the find command. For example, if I put in this input: my_find ~/homedir/ -name ...
1
vote
1answer
87 views

Shell script to change directory of terminal and open a second terminal

I am new to writing shell scripts and I am trying to write a script to CD to a folder where my programs are saved for one of my classes, then have a second terminal open that ssh's to a server used ...
0
votes
1answer
41 views

How can I multiply a column by a variable and write out? [duplicate]

I would like to multiply a single column in a .txt file by a variable and then write to another .txt file. What am I missing from the awk line? Appreciate any help in advance. !/bin/bash ...
8
votes
8answers
2k views

Is there a unix command that gives the maximum of two numbers?

I was looking for a command to limit numbers read in from stdin. I wrote a little script for that purpose (critique is welcome), but I was wondering if there was not a standard command for this, ...
1
vote
1answer
45 views

How do you derive a decimal from a math operation involving a variable?

I'm trying to find derive SCALEFACTOR which is basically 10000/(sum of 4th column in a file). How do I get a decimal from the output? Appreciate any help in advance. #!/bin/bash ...
1
vote
3answers
73 views

How do you parse through a subdirectory where the path contains spaces? [duplicate]

I'm trying to parse through a set of files in a directory on a mapped drive. However, I can't seem to resolve an issue that seems to be because of spaces in the path to the subdirectory. Would ...
0
votes
2answers
57 views

A batch that cout the number of occurrences

I've to extract the number of words using each letter of the alphabet from A to Z. The script that i've to create create take as parameter the name of the dictionary file to analyze and will be used ...
1
vote
2answers
74 views

Is there any way to make scripts dynamic? [closed]

I need my script to show the time till next run, continuously like a timer, is this possible?
2
votes
1answer
67 views

Bash script to detect uploaded files triggers many times for one file

I have a simple bash script setup that uses the built-in inotify daemon running CentOS 6.6. The script will simply echo the file that is upload to a specific directory. The script works but it echos ...
0
votes
2answers
61 views

help with bash scripting tput getting errors [closed]

I am a beginner to bash scripting. I need help to figure out what is wrong with this tput menu. #!/bin/bash tput setb 3 tput clear function main_menu { option=0 until [ "$option" = "4" ]; do echo ...
0
votes
1answer
162 views

bash if, then and else statement

I am learning bash, I ran into a small problem when trying to write a small script #!/bin/bash clear read num if [ "$num" -eq 2 ] then [ -d "/etc/passwd" ] | sudo cp /etc/passwd /home echo ...
1
vote
2answers
137 views

How do I automate opening Firefox over an ssh tunnel?

My university has access to some academic journals that I cannot access from home. To be able to download papers while I am away, my current proccess is: Create an ssh tunnel to my university ...
1
vote
3answers
76 views

loop test strings to see if input is valid for C program input

For example I have a file filled with some pretty gnarly strings. 12345678900 1111111111111111111111111 ...
0
votes
1answer
47 views

shell scripting and running after switching to other user

I have the following commands that I want to have them all in one shell file: su – s3 lizinfo.sh –b when the first linex executes, it prompts and the command prompt become like as below: ...
2
votes
1answer
95 views

Bash - Split quoted parameters

I have a script which gets called with two parameters: ./script.sh a b I'm currently reading them through $1 and $2 (such as cd $1). My problem is that the output needs to be the same for when the ...