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

learn more… | top users | synonyms (2)

1
vote
1answer
18 views

remove lines where a field's value is less than or equal to 3 - sed or awk?

I need to remove every line that has a value of 2 or less in the 8th field (column). My data looks like this: 12-31 Airport 189 379 41 49.70946503 -124.91377258 2 2880 30.8 01-01 ...
0
votes
0answers
8 views

Debian start script strips -f from command

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 ...
1
vote
0answers
17 views

Running a script during booting/startup; initi.d vs @root

I am currently trying to understand the difference between init.d and @root for running a script at startup/booting of the system. The use of @root is some what simpler by simply going into crontab ...
1
vote
1answer
29 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
27 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
36 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
43 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 ...
2
votes
5answers
153 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
18 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
38 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
38 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
26 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 ...
-1
votes
0answers
47 views

I'd like to write shell script to connect to database and delete the records automatically [on hold]

Can you please help me to write shell script which should delete records from my delete query and same will be appear in log file by saying record has been deleted. Also once this is done, it should ...
3
votes
1answer
46 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 ...
0
votes
1answer
12 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
40 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
14 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
147 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
65 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
28 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
88 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
69 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
62 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
41 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
56 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
44 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
21 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
23 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
38 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 ...
-2
votes
0answers
19 views

shell script to know the status of a node's application, whether it is up or down [closed]

I want to know the status of an application and application server which I cant get directly. It is like connecting to a server lets say 'A' and that server has many nodes say A1.A2,A3 and in that ...
1
vote
1answer
43 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
votes
0answers
28 views

Count how many times a word occurs in a txt file with awk

Basically i'm trying to count all instances of certain words that occur in a text file then printing the result. It has to be in done using awk. Im not really sure where to start. Any suggestions?
-4
votes
0answers
28 views

Random password generator [closed]

Make a random password generator: read 3 to 5 random lines from /usr/dict/words and assemble them together to form a random password. the command should takes an optional minimum size argument that ...
1
vote
1answer
48 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
41 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
46 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
60 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
237 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
46 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
69 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
28 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
31 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 ...
-1
votes
0answers
52 views

Send mail from BASH/SH file with mailx - mail is not being send

Hello I have this script in a file: #!/bin/bash # email subject SUBJECT="New_fish.app_available" # Email To? # Email text/message EMAILMESSAGE="/tmp/emailmessage.txt" first_line="There's a new ...
7
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
0answers
35 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
68 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
31 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
votes
1answer
21 views

Which files are associated with startup and shutdown scripts ? [closed]

AFAIK, the init is the first process that appears in userspace and from there it starts certain scripts which bring the PC into the desired starting state. Something analogous happens at the shutdown. ...
1
vote
2answers
70 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?