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

learn more… | top users | synonyms (2)

1
vote
2answers
364 views

Automatically entering ssh password from Busybox terminal

I currently am attempting to reboot a modem via ssh using a bash script. For reasons I don't feel like explaining, I NEED to start on an ubuntu server computer, ssh into a setup running busybox 1.21.1 ...
1
vote
2answers
101 views

Downloading multiple similar URLs using braces

#!/bin/sh orig=$1 var=${orig%.jpg} var=`echo "$var" | grep -o "[0-9][0-9]$"` cutten=${orig%[0-9][0-9].jpg} sequence='{1,' for i in `seq 2 $(( $var - 1 ))`; do sequence=$sequence$i"," done output=$...
4
votes
2answers
499 views

Combining records from two sorted files

I have two big files with more than six million records. Data in those two files can be correlated by UID (if ordering the file, should be at same row in both files). Eventually I need to get data ...
1
vote
1answer
40 views

Can I use the Rename utility to simplify this script that uses Find and Mv?

I use a script to automatically rename files according to a particular order: #!/usr/bin/env zsh pages=($(sed -n '/page_order/,/^$/ p' _config.yml | tail -n +2 | sed 's/ - //')) npages=${#pages} for ...
6
votes
1answer
320 views

Can bash files have machine language?

I was installing Anaconda Python on Linux. For Linux, Anaconda provide a bash script, but the file is huge, almost 300 MB. I decided to see why, and opened it in a text editor. About 95% of the file ...
1
vote
2answers
275 views

How do I get the date from two weeks ago using Solaris' date?

Linux uses: date -d "2 weeks ago" +%b which is equivalent in Solaris?, I searched online, but nothing.
0
votes
1answer
26 views

Auto launch a program on login for Raspbian or Debian

I am making a application on the Raspberry Pi, and I want it so if you login to the Pi directly, or through SSH, it will launch this application. This application is made to only work in the ...
0
votes
1answer
139 views

properties file source-in giving error

We have a simple shell script: myTest.sh, the contents are as follows: #!/bin/sh ################### file begins######################## . ./backupConfig.p.properties echo "success" ##################...
1
vote
1answer
166 views

7z is not excluding directories from exclude file

In a bash script I want to create an archive with 7z and exclude some directories. I created an exclude file that only contains one entry: excl_dir/ My script: #!/bin/bash archiveName="my_archive" ...
5
votes
2answers
173 views

Linux shell script delete specific contents in file

I have one file called abc.csv, its format is: aa,size:12 bb,size:13 cc,size:3 I want to delete size: , and the file will become like this: aa,12 bb,13 cc,3 Can anyone tell me how to use shell ...
1
vote
4answers
527 views

All files are not getting downloaded by SFTP script

I have a sftp file script with below details,my server folder like BCP11,BCP12,BCP13,BCP14.....BCPXX. In which BCPDUMP folder have files. Filename : file_sftp.sh #!/usr/bin/expect spawn sftp user@...
0
votes
1answer
52 views

How can I replace a filename with .ear in a file-list using sed?

I have a file whose contents look like: /appl/as/var/spool/ears/mps/ear1.ear ... I want to replace the name of only ear1.ear with ear2.ear and I am using the below sed command, but with no luck: ...
0
votes
1answer
38 views

How can I check for the actual time in a Script?

I want to check the time in a script. If it's between 06:00 am and 12:00 am it should output morning. If it's between 01:00 pm and 06:00 pm it should output afternoon. Between 07:00 pm and 10:00 pm it ...
1
vote
3answers
164 views

bash: grepping contents of column which is dynamic

I have data as following : What i need to get is the OS_NATIVE_NAME of a particular DEVICE. I know one way is to print its column value using: awk '{print $*col_num*}' But the column number ...
0
votes
1answer
1k views

BASH: Getting the md5 hash of file on remote server

Is there a way I could get the md5 hash of a file on a remote server? I'm looking for a command like md5 hlin117@server:/path/to/file.txt
0
votes
4answers
191 views

sed Remove lines ending in [0-9]%

I'm writing a script that logs stdout-stderr. The log contains multiple instances of: (Reading database ... (Reading database ... 5% (Reading database ... 10% (Reading database ... 15% (Reading ...
0
votes
1answer
36 views

Keeping first instance of duplicates when column values are interchangeable

I have previously asked a question about keeping the first instance of duplicates and the solution provided has been working perfectly until now (see Keeping first instance of duplicates). However, I ...
1
vote
1answer
78 views

What does =~ mean? [duplicate]

Ran across a shell script that had '=~' in a contitional and I was wondering what it meant. Not much luck on Google or SO sites. Example: if [[ $VAR =~ 'this string' ]]
-1
votes
4answers
205 views

How to grep AND pattern with pipe

I wrote a piece of script similar to something below: srvc_location=`ps -ef| grep '${sandbox}.*pset' | head 1 | awk {print $9}` echo "SERVICE LOC : "$srvc_location But strangely this $srvc_location ...
4
votes
3answers
324 views

Given two background commands, terminate the remaining one when either exits

I have a simple bash script that starts two servers: #!/bin/bash (cd ./frontend && gulp serve) & (cd ./backend && gulp serve --verbose) If the second command exits, it seems ...
2
votes
1answer
35 views

How to detect that all the child processes launched in a script ended?

I wanted to launch several commands in parallel by using a for loop, each command can take more or less time, and I want to call another command at the end of the script. Here is a minimal example: ...
3
votes
4answers
737 views

how to change one column and add other columns in a row by awk

I have a file MDD.TXT with following records. file : MDD.TXT 0|ABC|055309|20120929053309|11965150 0|ABC|061434|20120929063434|11155537 0|ABC|070228|20120929073228|11965150 0|ABC|082213|...
1
vote
4answers
507 views

Bash: move files of specific pattern

I write a script that iterates over a set of zip files, extracts them and moves only files that match a specific filename pattern to another folder. The script: #!/bin/bash ARCHIVE_FILEMASK="????-??...
1
vote
2answers
92 views

`last` alternative showing logins only for current user

I'm aware that I can use last $USER, however this won't work correctly or securely on machines with many users - no user should know another users IP or when they logged in. Is there a known solution ...
-1
votes
1answer
314 views

Forwarding return value of shell script to C/C++ [closed]

I tried to find possible solution on Google, but all I found is explanation on how to return value, but not how to accept it in some programming language, in my case C/C++? Does anybody have idea on ...
1
vote
1answer
41 views

How do I convert a batch of avis into mp4s?

I have several avi files in the one directory that I would like to convert to mp4s using avconv. Now I know the basic procedure of how to do this, manually, for each avi, namely (where $@ are the ...
2
votes
1answer
272 views

Rsync backup script for multiple servers

I have simple script that backing up data from remote server via ssh using rsync. I have external config file for that. In this config file I have variables: OPTIONS, REMOTE_IP, SOURCE and ...
0
votes
3answers
207 views

find number of files that I can both read and write

How would I count the number of files in a given directory that the current user has read permissions and write permissions on ? I am starting with: echo "whats the directory you want to check ?" ...
0
votes
1answer
39 views

Output piped command to variable

I'am trying to write a small script to create an JSON File. I have to store SSL Certificates inside this json, so i have to convert the CRT/KEY file to the required format. Is there a Solution to ...
1
vote
2answers
478 views

Extract data between two matched patterns in a binary file

I am trying to extract a jpeg image from a binary text file. I want to extract all data between 0xFF 0xD8 (start of image) and 0xFF 0xD9 (end of image) inclusive. Earlier, I have successfully run the ...
0
votes
1answer
208 views

Unix zip command junk-paths flag not working on same file names [closed]

I have the following file structure: cwd/ ---dir1 ---file_name1 ---some_file_name ---dir2 ---file_name1 ---some_other_file_name ---some_file I want to get ...
0
votes
1answer
84 views

How to limit the size of log files which are generated by scripts runs at startup

So, how can I limit the log file size or how to automate to delete the files, if the files are reached a particular size. Here is the actual scenario PLEASE CHECK HERE. For testing, I deleted log file ...
0
votes
1answer
400 views

How to print the values of variables with incremented numbers using a loop in shell script?

I have a Bash script where i have calculated many values and stored them in the variables which have a number for each row. For instance, i have a variable named as TC_5 which calculates the value of ...
1
vote
3answers
2k views

pass parameters to bash script using chef attributes

I have a bash script ( let's say main.sh ) which I need to integrate with chef. Currently we are using "expect" to pass the parameters to main.sh. Now I need to make script in such a way that the ...
2
votes
2answers
377 views

Copying latest modified file from multiple directories

I have directory structure adc/asd/abc.20150918_150635.gz, adc/asd/abc.20150921_140748.gz .... (where .gz file names contain time stamps of its creation). Many other directories similar to asd are ...
0
votes
2answers
172 views

how to declare command line variables in shell scripts?

I want to declare the variable as a command line argument for a shell script just like ./script.sh file=/tmp/domains.txt domain=abcd.com** help to do the same.
1
vote
1answer
538 views

Conditional Check for IPTables

I am trying to check whether specific rules in IPTables exists or not. #!/bin/bash if iptables -L -n | grep -- "ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:8880"; then ...
0
votes
0answers
40 views

Connecting Shrew using terminal

I am using Shrew in CentOS to enable VPN tunneling. I use the following to start it. iked qikea Now I want to enter username and password also from terminal. I don't want to use the GUI so that I ...
2
votes
1answer
146 views

Background vs foreground task and running tasks in parallel

Since I'm new to Linux, apologies if I'm not using the correct terminology. I'm trying to run a number of tasks in parallel (using the background shell operator). However, I need to first run two ...
0
votes
1answer
24 views

Avoid being assigned to a particular node in cluster

I am using the department's cluster which adapts the pbs queuing system to run some mpi programs. Are there any ways that I can avoid being assigned to a particular node when submitting a job via qsub ...
0
votes
1answer
95 views

Compare size of file system

How to compare size of file system on 2 different servers Eg: Server1 Filesystem GB blocks Free %Used Iused %Iused Mounted on /dev/prddatalv 40.00 18.32 55% 65 1% /u01/...
1
vote
1answer
31 views

How to recursively add zeroes to a file name [duplicate]

I have a folder with these files: 03.jpg 04.jpg 05.jpg 99.jpg I want to rename these files to 003.jpg 004.jpg 005.jpg 099.jpg by using a bash script. How can I do this?
4
votes
3answers
75 views

Script that outputs the total number of lines in all the text files that are passed as arguments

So I'm working on a script that will accept arguments that are text files, and should output the total number of lines in those files.  For example, if I say ./myScript file1 file2 file3 it will ...
3
votes
1answer
148 views

sudo script - best practice?

I have a script in which some of the commands need to be run as sudo. I have seen it asserted that running sudo inside scripts is a bad idea, and that is is better to run the whole script as sudo (and ...
3
votes
2answers
107 views

Sorting image files using header information

I have multiple image files inside a directory having the same extension (.mrc). In the terminal, if I do, header , it gives following output: RO image file on unit 1 : ...
14
votes
5answers
1k views

Is this a bug in bash? `return` doesn't quit function if called from a pipe

I'm been having some weird problems with bash lately. While trying to simplify my script, I came up with this small piece of code: $ o(){ echo | while read -r; do return 0; done; echo $?;}; o 0 $ o(){...
4
votes
1answer
243 views

Predicting the PID of previously started SSH command

This is the weirdest thing. In a script, I start an SSH tunnel like so: ssh -o StrictHostkeyChecking=no -fND 8080 foo@bar This starts an ssh instance that goes into the background, and script ...
0
votes
0answers
95 views

Raspberry Pi to Computer - Scripted File Transfer and Deletion

This is my first ever bash script and I've done the best I could to find most of the answers on my own, but I have finally come to a road block. This script seems to (mostly) work, but I am not ...
1
vote
1answer
59 views

AIX Non GNU tool for text replacement

Contents of the file : PS1="$(hostname):${LOGNAME}:\${PWD} ${PROMPT} " PS1="${FGOLD}$(hostname):${LOGNAME}:\${PWD} ${PROMPT} ${NORMAL}" PS1=abd PS1="$(hostname):$LOGNAME:\$PWD $PROMPT " export PS1 ...
0
votes
4answers
484 views

How to skip the first argument in a script

Linux Pocket Guide has a nice example on how to go over all the arguments in a script for arg in $@ do echo "I found the argument $arg" done I am writing a script in which all the arguments will ...