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

learn more… | top users | synonyms (2)

1
vote
2answers
32 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
23 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
2answers
20 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
35 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 ...
0
votes
3answers
24 views

How to determine callee function name in a script

to make it short, doing s.th. like -bash$ function tt { echo $0; } -bash$ tt yes, $0 will return -bash BUT how to get the function name called, i.e. tt in this example instead?
0
votes
0answers
19 views

i am new to shell scripting..how to do a multiple backup's of a file in a sequence which is overwrting through shell scripting? [on hold]

Eg : Backup.txt in /tmp path backup1.txt, backup2.txt..etc even same file to write to sequential folder also is ok. eg : backup.txt to s1,s2,s3..etc
1
vote
2answers
82 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
26 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
5 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
29 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
27 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
35 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
33 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
21 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 ...
2
votes
2answers
47 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
25 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
31 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
38 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 ...
0
votes
1answer
17 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
37 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
40 views

how to login a user using shell script [on hold]

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
25 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
45 views

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

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
2answers
30 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
63 views

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

I want to keep only header and trailer records in a UNIX file.
1
vote
3answers
124 views

How do I run a command in a different tty?

Suppose there are two terminals, pts/0 and pts/1. In pts/0, I have fired a command: ls>/dev/pts/1 Then, we only get the output of the ls command in pts/1, but I want to run a command as well as ...
0
votes
2answers
45 views

Need help in data arrangement

Could you please help me to sort this out, I have data which i would like get output in below format using shell/perl script. Data: Virtual Machine Test status Running. Assigned Server ...
1
vote
2answers
57 views

Stop bash script with any key

I'm writing a custom gnome-terminal profile which I want to stop with any key I choose. After pressing the key, my intention is to complete all my commands at that moment and start su. I've tried ...
1
vote
2answers
19 views

Trying to direct variable contents into command gives Ambigious Redirect

I'm trying to write a script which tests the http response from various Node servers I have running and which then emails me if any respond with a 502 error from Nginx (meaning one or more server has ...
2
votes
0answers
8 views

i3status script that change its text by itself

I am trying to add a block for rss the latest news in my status bar. The news is composed by a title and a description. The full text doesn't fit in the status bar, so I would like to make it read ...
-3
votes
0answers
16 views

Removing intermediate line breaks in muliple columns except the last new line character [closed]

Suppose If I have the data like this Col1|Col2|Col3 <br\> 123|abc\n<br\> xyz\n<br\> |abc\n<br\> def\n<br\> other rows<br\> <br\> In the above newline ...
1
vote
2answers
36 views

tr -d not work with carriage return

I want to get rid of \n from variable I found many answers for that which say "use tr -d" but tr -d not work for me echo "$test" | od -c 0000000 4 4 2 5 2 \n 0000006 then I use tr -d ...
1
vote
3answers
50 views

if always false with equal variables

I first get file size info with curl fileSize=$( curl http://linux.die.net/include/sys/ioctl.h --head | grep Content-Length | awk '{print $2}') echo $fileSize is 1825 then I download the file and ...
0
votes
2answers
38 views

Why is crontab giving me a permission error message when I copy my backup?

I use a PuTTY session to copy my nightly backups to another location. I log in as the root user and change directories to /store/BackupLocation which holds backups from the last 100 days. I can then ...
0
votes
1answer
41 views

Kill a running shell script, and kill all process running within it

I have a shell script running in the background, which runs 5 different jobs. When I run the shell script all 5 jobs start running in order. When I kill this shell, whichever process is running, will ...
0
votes
4answers
38 views

Catching the last returned value in Unix

please help me with this. I am doing a grep test file.txt and I want to catch the whole value and print it.I am doing this, grep test file.txt if [ "$?" -eq 0] then echo success else echo fail fi ...
0
votes
1answer
21 views

Execute a function before specific programs

This began with the want of adding SSH keys to ssh-agend on demand, but because this isn't possible with OpenSSH, I came up with this zsh script instead. But for a reason I can't figure out, instead ...
4
votes
2answers
66 views

Search directories for multi line string

Looking for a way to recursively search a repository for all files containing a multi line string and return the file names that contain it. The paragraph is just a header approx 30 lines. So I know ...
1
vote
3answers
42 views

Bash script for service to check mount before start

I need to insert on some service scripts a condition on the top to check whether a device is mounted or not. I'm not very familiar with bash script... This is a first try I wrote but it doesn't ...
2
votes
3answers
198 views

awk : parse and write to another file

I have records in XML file like below. I need to search for <keyword>SEARCH</keyword> and if present then I need to take the entire record and write to another file.(starting from ...
0
votes
2answers
86 views

For loop cannot distinguish * syntax

set -x for f in ~/1/2/*/*_1.txt; do subdir="${f%/*}" pushd "$subdir" &>/dev/null file="${f##*/}" expTool INPUT1= "${f##*/}" INPUT2= "${f%_1.txt}_2.txt OUTPUT1= "${f%_1.txt}_3.txt" OUTPUT2= ...
3
votes
3answers
323 views

How to sleep until a given date & time?

I want to write a shell where given a date (day-hour-min) e.g. 10:00 AM Sun 2:30 PM Mon ... It sleeps until that exact date & time. I thought one way of doing it is, I could get the current ...
1
vote
1answer
34 views

timeout doesn't work with accumulo shell in bash script

I'm trying to check if a scan of an Accumulo table times out (to see if the table is corrupted). #!/bin/bash timeout -s KILL 20s accumulo shell -zi myInstance -u root -p secret -e "scan -np -t ...
-2
votes
0answers
23 views

Restarter script error in archlinux

I was running a autorestarter for some traffic exchange when this error occured to my VPSs " blah blah blah [26678:26678:0203/150900:ERROR:process_singleton_posix.cc(268)] Failed to create ...
0
votes
0answers
42 views

Unix scripting : Writing to another file with “:” is failing

I have below record (and many other such records) in one file 9460 xyz abc (lmn):1027739543798. Taxpayer's identification number (INN): 123. For all IIB. 2016/02/03 I need to search ...
0
votes
0answers
26 views

Nginx Performance Monitoring: How to collect CPU, Memory and Disk Utilization data?

I'm relatively new to shell programming and I need to collect statistical data on nginx web server performance running on Linux VMs for further analysis. I have checked some tools and I find dstat ...
1
vote
1answer
25 views

Cron Job Hourly Except Certain Time Frame on Friday

I want my cron job to run every hour, every day except Friday when I don't want it to run at all between the hours of 2am-9am (but hourly outside of this timeframe). Ideally, I'd like to have this in ...
0
votes
0answers
4 views

Power/Session -> New Session from bash script (KDE)

I would like to ask, probably trivial question, yet I was unable to find what is required. Suppose I click Power/Session->New Session from launcher, KDE gives me possibility to login as another user. ...