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

learn more… | top users | synonyms (2)

2
votes
1answer
32 views

Why are these nested options in a POSIX shell script being word-split?

I have a script count_args that counts arguments: #!/bin/sh echo $# If I call it with these options, it tells me it gets two arguments: $ ./count_args --options '1 2' 2 But if I construct the ...
2
votes
4answers
107 views

How to escape shell metacharacters automatically with `find` command?

I've bunch XML files which I would like to move to corresponding folders with the same name. Here is sample structure (in shell): touch foo.xml bar.xml "[ foo ].xml" "( bar ).xml" mkdir -p foo bar ...
1
vote
1answer
21 views

What does <(command) do? [duplicate]

I was reading this script someone wrotte and there is this line: comm -23 <(grep cat access.log) cats | mailx -s subject address@gmail.com I understand it to mean convert this output as if it was ...
0
votes
1answer
32 views

How do I remove a line if it begins with a . or a > using sed?

For the life of me I can't get this to work properly (forgive me if this is a trivial question). I have a text file that have lines that begin with either a period, ".", or a right arrow, ">". I need ...
0
votes
1answer
11 views

How to define a shell variable as equal to the version of Vim presently installed?

I am intending to write a shell script (if specifics are required, it will be executed in Zsh) that will determine the latest Vim patch via running: git pull origin master vernew=$(git describe ...
1
vote
2answers
15 views

How to reverse sort the output from grep -rc

I want to be able to sort the output from the grep -rc command, I am currently using the command: grep -rc "Pattern" . | sort -t: -rk2,2n however the list is still sorted from low to high, ...
0
votes
1answer
18 views

How to get pulse sound level

I'm using simple keyboard shortcuts to adjust sound level on my fluxbox 123 :Exec amixer sset Master,0 5+ 122 :Exec amixer sset Master,0 5- However I'd like to add some notification (notify-send) ...
1
vote
1answer
30 views

How to assign a variable within a pipe

I'm building a one liner in bash. If making a script or writing temp files were an option, I wouldn't need to ask. I need to assign a variable in the middle of a set of pipes to use down the line. ...
0
votes
1answer
21 views

how to concatenate Login, pwd and @server variables?

how to concatenate Login, pwd and @server variables ?? ex: export Login_va="Login" export pwd_va="pwd" export server_var="@server" echo whenever sqlerror exit | sqlplus ...
0
votes
1answer
34 views

Delayed Expansion

I wanna make a quine .sh script, and this is what I've made so far: quine.sh: #!/bin/sh q="#!/bin/sh\nq=$q;echo \$q";echo $q Focus on this line: q="#!/bin/sh\nq=$q;echo \$q";echo $q At the first ...
0
votes
1answer
31 views

How to hide Login/Pwd into shell?

I've a Shell script(.run) that let me to connect into Oracle sql : echo whenever sqlerror exit | sqlplus Login/Passwd@SERVER @"TABLE1.sql" echo 'return code : ' $? I'd like to hide ...
4
votes
6answers
67 views

Sort files by highest number in filename

I've got a bunch of files all named like this: name_file-1.txt name_file-2.txt name_file-3.txt some_other_file-1.txt some_other_file-2.txt There are thousands of different filenames, some with just ...
1
vote
1answer
43 views

How to handle sub-command line in shell script?

I am new to Linux and I am doing a Bluetooth Low energy project using the Intel Edison. The Edison has a Yocto 1.6.1 on it. I used Bluz and gatttool to connect my BLE sensor. But I need to type the ...
0
votes
3answers
22 views

How to bulk compress different sub-folders?

I have a folder all_folders which contains 5 folders: ./all_folders ./all_folders/folder1 ./all_folders/folder2 ./all_folders/folder3 ./all_folders/folder4 ./all_folders/folder5 Can I compress all ...
0
votes
1answer
24 views

Reading file using shell script, format of the line has changed

I am reading a file using the following code: displayLine(){ echo $line } filename="SampleFile" while read line do displayLine $line done < "$filename" The format of the file that I am ...
0
votes
4answers
45 views

Grep for a string and then echo a string back from a record

I have the following record: MiraServ.log.10:2016/02/07 15:25:13 3 All stations busy!! MiraServ.log.10:2016/02/07 15:25:13 1 TranHasError (3627,-2) ...
2
votes
1answer
29 views

Inside a bash script doing an ssh, automatically add the host only for certain known RSA keys

I have a Chron job running a bash script that then SSH's to a my server. But my server's IP address changes from time to time (my bash script has a way of finding looking up the new IP address). But ...
0
votes
1answer
21 views

Remove file name when recursively counting number of occurrences of a pattern

When I run my grep command: grep -rc 'PATTERN' . it prints out the number of lines that the pattern occurs, but it looks like this: ./hotel_232424.dat:234 and so on... How would I remove the ...
0
votes
0answers
34 views

How to execute a command after ssh login via batch file

I want to execute a set of commands at once I login to a ssh session everytime via a batch file. Eg: start putty.lnk -load "session" -ssh username -pw password -m <commands> Here I am using ...
-1
votes
0answers
27 views

bash shell scripting - How do I check the values stored in a variable? [on hold]

I ran the code below that returns the number of results as 14 which is correct. NUMBERRESULTS=$(curl -s "privateserver:3000/devices/restful_api_device/… jq '.[]|length') echo ...
-1
votes
1answer
29 views

Need a script for adding bulk IP aliases in CentOS [on hold]

Need a script for adding bulk IP aliases in linux server (CentOS 6.7) As we manually add for eg. ifcfg:eth0:1 but adding 150 to 200 interfaces manually is a lengthy work. SO need a script which will ...
-1
votes
0answers
30 views

Decrease time taken to execute script remotely [on hold]

I have 2 scripts on my prod AIX server, one to suspend db and another one to resume db. When I run the scripts from the prod server the suspend and resume completes in 2 secs. For backup purposes I ...
0
votes
1answer
38 views

Convert a column of epochs into a time column starting from 0

What I have Hi, imagine a lot of this files, where first column is epoch, and the other(s) column(s) are some data: 1000333,34,1 1001456,56,0 1005356,34,2 What I need I need to transform them ...
3
votes
2answers
129 views

Is there a way I can grep recursively over all the files in the current directory to find a pattern and then print it in order of high to low?

So so far, the code looks like this: grep -rc 'Author' $1 It prints out all the files in the directory, which is taken as an argument. However, how would I sort the output (for example): - ...
0
votes
0answers
33 views

Multiple sed commands in a file

I want to save a .txt file to 2 separate .txt files using command placed in a .txt file. I can use sed -e '1,20 w file1' -e '21,$ w file2' input.txt But how would I plac e this command in a file ...
0
votes
3answers
29 views

Backup script fails with the rsync command's options in a quoted variable

Using: rsync version 3.1.0 protocol version 31; Linux Mint 17 (based on: Ubuntu 14.04.3) In one of my backup Bash scripts, which uses rsync, I put the rsync options in a variable like this: # Set ...
1
vote
1answer
43 views

How while loop execute in the shell script for the FALSE condition?

I tried it with some example but it is not clear to me. FIRST EXAMPLE #!/bin/bash i=0 while [ $i -lt 10 ] do echo "$i" i=`echo "$i + 1" | bc` done output ===> 0,1,2,3,4,5,6,7,8,9 now ...
1
vote
3answers
38 views

How to determine callee function name in a script

To make it short, doing something like: -bash$ function tt { echo $0; } -bash$ tt $0 will return -bash, but how to get the function name called, i.e. tt in this example instead?
1
vote
2answers
94 views

What do you use when you can't use Bash? [on hold]

I am trying to make a shell script that runs on a widest variety of *nix systems. So, if I wrote a bash script backwards compatible with old versions of the shell, but what if bash wasn't on the ...
0
votes
2answers
40 views

Check if a file contains a certain pattern?

#!/usr/bin/expect -f ps ps -ef > test.txt Now if I want to check whether test.txt has certain keywords present, in it, how do we go about? say: 'apache' or 'fast' Can we use the if statement ...
0
votes
0answers
6 views

db2 cursor in shell script

I want to select a row from table in db2 DB and check for each column value like while col1 = do else . I cannot direct the text to a file and use it. Can some one tell me how can i do this?
1
vote
1answer
45 views

Logrotation of a file

I want to rotate a file and place the rotated file inside a new directory called 'backup'. The rotation of the log is working fine where the rotated file is not getting moved inside the backup ...
1
vote
1answer
30 views

Comparing original & backup folder, then deleting non-existing files

I'm using Raspbian jessie (ubuntu). I made a .sh that makes a backup .img of everything (excluding mnt, tmp, run, dev, boot, etc.) and let this run once a week with crontab. It checks for modified ...
1
vote
1answer
56 views

How do I maintain sudo in a bash script?

If I run this script, how do I pass super user permissions to it? I wrote this just to setup new machines with the basics. I don't want to run every command with elevated permissions, but the commands ...
1
vote
3answers
36 views

Joining two parts together to make a single script

I'm trying to create a script to do the following: extract the magnet link from a lynx bookmark and then use it as part of a curl command. like this: curl ...
1
vote
1answer
23 views

Issue with resize and stty on remote ssh script?

Scenario: Source host (Solaris 5.10, KSH), im trying to run the following script named sample.ksh on source #!/bin/ksh set -x Rediscover () { ssh user@hostB ./scripts/test.ksh } Rediscover exit 0 ...
3
votes
2answers
54 views

Bash script to extract some information from Ebay HTML pages

I would like to filter the output of a search on ebay which I've exported to a text file. There are a number of results in the search but I've included just one example at the bottom of this post as ...
0
votes
1answer
27 views

Give the command to remove duplicate lines in a .txt file and save the new file as new.txt file

I'm trying to do this but I cant create the file. I enter: sort myfile.txt uniq -u | tee newfile.txt and It wont create the file automatically. What am I missing here?
0
votes
3answers
39 views

Can I compare the parameter of a script to an array of variables and process it?

I want to manipulate the expanded value of a variable that has been selected from an array after user input. Here's what I mean: $ ./myscript.sh url2 #!/bin/bash array=(Sigil wp2epub csskit) ...
-2
votes
0answers
42 views

Script for logging in to multiple servers and running some commands [on hold]

I have a list of host/server names in a text file. I want to log in to each host using SSH and run certain commands. I'm using password authentication. When ssh'ing to another server, how to handle ...
8
votes
1answer
88 views

Trap Ctrl-C in awk script

I believe Ctrl-C can be trapped in bash scripts. Is it also possible to trap it inside an Awk script in order to handle that event? For example, for aborting processing, but printing the results of ...
0
votes
1answer
18 views

How to prevent garbled screen display while running scripts on remote hosts?

Current scenario: I am trying to run Unix shell script from a solaris 5.10 box, within the script one of the tasks is to ssh to another Linux host (ssh-key pair already setup) and run a set of ...
1
vote
2answers
23 views

How do I create a rule for custom flag replacement with C shell?

I want to have the following behavior with grep: grep --java <rest of the command> Where --java would either dynamically convert to --include=*.java or internally be equivalent to it. Is ...
2
votes
1answer
39 views

Adding folder name to .zip files inside it

I have file1.zip, file2.zip, etc. in folder called folder1. have similar folders folder2, folder3, etc. I need to add folder name to each .zip file inside these folders. So, files inside folder1 ...
-1
votes
2answers
47 views

how to login a user using shell script [closed]

In my computer i have two user(tiger,jenk) now i want to create a shell script for login user "jenk" from user "tiger" i m try this code [tiger@pagaltiger mytask]$ echo -e "IncorrectPassword\n" | ...
0
votes
2answers
27 views

Exec vs source error on ==

I run a strange error with the following code: #!/usr/bin/env bash a="a" b="a" if [ "$a" == "$b" ] then echo "Eq" fi chmod u+x script.sh Then executing the file will display Eq: $ ./script.sh ...
2
votes
2answers
46 views

How to ensure echo into a file has been flushed? [closed]

I have two co-operating programs X and Y running on the same system. X some times uses Y to calculate some information. I use file based communication between the programs. When X wants Y to compute ...
0
votes
3answers
35 views

How do I search a directory of data files and print out how many times a certain word appears in each file?

This is what I currently have, however it prints the total number of times Author appears in all of the files: 128367 grep -roh 'Author' $1 | wc -w However how do I print out the word count for ...
-2
votes
1answer
44 views

KSH for generating 'n' of rows for a table dynamically : Issue with if else statement

I need to generate billion of records in a text file for table loading purpose. My destination table defination is: CREATE TABLE txnrecords12( txnno int, txndate string, custno int, ...
-1
votes
2answers
68 views

How to delete all the lines in a UNIX file except first and last line? [closed]

I want to keep only header and trailer records in a UNIX file.