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

learn more… | top users | synonyms (2)

2
votes
1answer
139 views

send ctrl+q to a process in bash [closed]

I am writing a script to load .torrent files with rtorrent. I can get them to load fine, but the rtorrent command loads up its console each time. The console can be quit with ctrl+q. Is there a way I ...
2
votes
1answer
203 views

chmod doesn't work on Mac

I have a very simple question. I cannot make a file executable from the command line on a Mac. This is what I'm typing in terminal cd ./Desktop echo 'say hello' > hello chmod +x hello hello It ...
1
vote
0answers
63 views

Cron “cowardly” refuses to run a job [closed]

I have a strange issue running a script via cron. I've got it installed on several identical machines(CentOS 6.5), some are working some are not. the job it self looks like this * * * * * /usr/local/...
1
vote
2answers
52 views

source file as an argument?

I've read up on using source to run another file inside another: source ./filename but I want to do this inside a command as an argument.. (or set of) Here is how the command goes: command \ -...
3
votes
2answers
68 views

Making an Extra Copy and Paste Script

How can I make a script which duplicates Ctrl + C and Ctrl + V (aside from the actual keybinding part, which I know already I can use xbindkeys for)? So, for example, how could I make bash functions ...
2
votes
1answer
48 views

Confine the directories in which a script will act

For example I have a script looks like: for i in */*/ do cd $i cp POSCAR.ideal OSZICAR .. cd .. rm -r */ cd ../; done to remove subfolder of a folder, however with a bit of uncautious, for ...
0
votes
1answer
60 views

If and else statement using diff -q

So I'm trying to write an if else statement which involves the use of diff -q. So, let's say I have two files hi.txt and hello.txt and I store them into variables called hi and hello respectively. I ...
0
votes
2answers
200 views

Using xargs to copy text into an array of files

I'm trying to copy the output of a file into multiple files using echo, xargs and cp. My problem is xargs is only printing to the first file in my array instead of printing a copy to all 3 files. Am I ...
1
vote
1answer
28 views

Interactive bash script

I'm writing a script that shuts down the Apache service, performs a function, and turns it back on. I'd like to get some type of interactive confirmation for each process. I'm not familiar with ...
0
votes
0answers
312 views

How to write a script with Android Debug Bridge command in it

I am trying to write a script to automate some testing, and the fist step is connect to my device and update the /lib/modules/ directory with the recent version of a device driver on my host. That is ...
0
votes
1answer
138 views

Testing using shell scripts

I am trying to write a shell script for testing my programs. I am having a few fundamental questions regarding it: Goal: The shell script must be able to test certain programs and determine if they ...
0
votes
2answers
559 views

Initializing a variable with echo

So, I'm trying to store a part of the name of a file into a variable for other uses. So, if my file was named hello123.txt and I want to store the 123 part. So I try num= echo $file |cut -c6-8 ...
3
votes
2answers
82 views

Bash passing input

I am using an open source tool to merge files with genomic ranges (Feature to similar to R language function 'merge'). The software can take only two input files at a time. Suppose if I have to merge ...
1
vote
3answers
111 views

one liner to get memory usage

Looking to do a one liner to tell the total amount of free memory on system including swap and cache. free -t isnt an option so i have to do a sum of the values under the free column I'm not sure ...
3
votes
1answer
163 views

How to export function defined by eval?

Define a dynamic function by running this in command line: eval "ab() { echo test; }" It runs and prints test. Put the same statement in a script test.sh and then execute the script. Nothing ...
0
votes
0answers
69 views

rsync failed on SSH even after changing Maxstartup option in sshd_config

I am using following command to copy file from another system. sshpass -p 'XXXXX' rsync --partial -avvvv --inplace --rsh=ssh -e 'ssh -vvvv -p 62002 -o StrictHostKeyChecking=no -l username' 127.0.0....
2
votes
2answers
85 views

Rename files in bash script

I am writing a script to rename my files, The current syntax for filename is program 1.c and I want to change this to cprogram-program1.c. I am unable to get this format. Few conditions for ...
0
votes
1answer
52 views

how to extract some rows in a data file by comparing with another data file? (merging) [duplicate]

I have 2 different file : first file: id1 19501112 id2 19831207 1d4 20001212 id6 20000101 id10 20061213 id11 20081212 id12 20100109 id13 20101218 id14 20101212 id15 20111111 id16 20150919 id20 ...
-3
votes
1answer
306 views

Syntax error in a ksh script: `2' is not expected [closed]

I am trying to get the MD5 of some ears in a Unix box using the fanout command but there are some errors. My code is: ears=ear1-ear2 cluster=abc dmgr=server1 k=$(expr `echo $ears | grep -o "-" | wc ...
0
votes
2answers
83 views

select and move the contents to another file

I have a file with the below contents. All I need to do is filter the ALTER script that has UNIQUE keyword in it and move it to a different file. I tried using sed -n '/ALTER TABLE/,/UNIQUE("ID");/p' ...
0
votes
0answers
38 views

How to restore sbatch array job output file names to their original names

In order to submit array jobs using Slurm, I've renamed hundreds of files with incremental numbers using the following command: COUNT=1 for file in ./*; do mv "$file" "${COUNT}" let COUNT++ ...
1
vote
3answers
569 views

watch a file and compare checksum

Trying to get a script to watch a file and compare the md5sum of the file every 60 seconds, if it has changed then print a warning to the screen Not sure on how to go about this. This is what I have ...
2
votes
3answers
1k views

Get script to run again if input is yes

I am putting together a simple file handling script, its all working nicely except at the end , I want it say do you want to perform another action and if the answer is yes then I want the script to ...
1
vote
2answers
188 views

Find and replace a string if particular pattern is found in a line

All I need to do is, search for CCSID in this file, wherever it finds CCSID, the CHAR in that line should be replaced with NCHAR and VARCHAR in that line should be replaced with NVARCHAR2. I tried ...
2
votes
2answers
98 views

Exchanging One Column From File1 with files from File2

I have two files. The first file has 11 columns, for example: 1 2 3 4 5 6 7 8 9 10 11 The second has 10 columns and might look like this: 11 22 33 44 55 66 77 88 99 100 What I want to do is look ...
0
votes
1answer
200 views

How to delete the lines that starts with a specific word and end with a specific word

Eg: CREATE TABLE COMM.ACL_ENTRY ( ACL_OID CHAR(18) FOR BIT DATA NOT NULL , USER_DESC_TYPE FOR COLUMN USER_00001 BIGINT NOT NULL , USER_DESC_OID FOR COLUMN USER_00002 ...
18
votes
2answers
2k views

What is the difference between * and *.* while copying?

What is the difference between following 2 commands? cp -rp /dir1/*.* /dir2/ cp -rp /dir1/* /dir2/
0
votes
2answers
121 views

Manually entering a password

The script is working: #!/bin/sh echo "Enter Server IP Address" read IP echo 'mypassword' | sudo -S ssh $IP </home/myscript.sh How do I modify it so I can manually enter the IP address, and ...
4
votes
2answers
346 views

Putting process substituted file descriptor into variable

I have long command roughly this: $ command-outer "long command which references a file here: filename1, and another file reference here: filename2" The files are the output of another command. So ...
1
vote
1answer
215 views

Storing part of command line arguments into user array

I am able to do this, array=(2 46 7 4 2 1 1 1 23 4 5) store=(${array[*]:5:5}) echo ${store[@]} # print 1 1 1 23 4 5 Now instead of extracting the 5 elements from position 5 from a user array, I ...
0
votes
2answers
37 views

Looking for files ONLY in subdirectory

So let's say I want to search for files that are C files. How do I go about searching for them ONLY in my sub-directories? I tried: ls -R | egrep .c$, but that also searches for .c files in my ...
4
votes
3answers
1k views

Why is my function call not working when returning a boolean?

Why is my function call not evaluating to boolean in the if condition below? Do you have to use numerics for boolean when returning from function call? #!/bin/bash #Script to wait for log file to ...
1
vote
2answers
358 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
498 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
270 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
138 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
172 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
524 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
51 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
163 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
190 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' ]]