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

learn more… | top users | synonyms (2)

0
votes
0answers
5 views

Bash Scripts arguments and G++ static and dynamic library generation

I have a library named matrix.cpp that is used by a program named test.cpp. Now, I want to write a BASH script which takes matrix.h and matrix.cpp as input and generates matrix.a and matrix.so ...
1
vote
1answer
8 views

need a detailed guide to start scripts and applications in xfce4

I am looking for a detailed explanation about where is the right place to start scripts applications during the boot process. It seems there is either confusion or not need for the detail I am looking ...
2
votes
2answers
45 views

Need to obtain Awk output in specific sequence

Data in file: 1234567-5678907 3456789-1234563 3456789-1234567 . . . . n Now I want the output in the below format: 1234567-5678907,3456789-1234563,3456789-1234563....n I have used below command ...
1
vote
1answer
61 views

Bash script won't work on current directory

I'm using Kali linux which is based on Debian and wrote an script to copy some files from where the script is based to a specified directory. But when I execute my script (called CopyFiles.sh), cp ...
-1
votes
0answers
16 views

useradd -c “Text” username does not work when reading data from a file [on hold]

useradd -c "text" username works only from within a script when parameters are passed to the script on the command line, but when the parameters are read from a file, it doesn't work
2
votes
3answers
56 views

Command line options with argument in shell script

I have a script to get ldap user name, email and mobile number: #!/bin/bash echo -n "Enter Unix id > " read UNIXID ldapsearch -x "(cn=$UNIXID)" | awk '/givenName/||/mobile/||/mail/' Here is the ...
2
votes
1answer
30 views

ksh/bash Formatting Files through sed by cat file|sed command

I am new to unix platform, (Alternate Approaches can be discussed) I am trying to change the colors of content of a file conditionally. My file is: A B C D Value Value Value Value Value ...
0
votes
1answer
35 views

insert value from reference file

I have a daily csv file with thousands of rows. I have been asked to concatenate two columns, then insert a new column when a value in a given column matches a table from another file. Empty values ...
4
votes
2answers
178 views

Best and short way to run a program if another is not installed

I have this code: #!/bin/bash num=${1:-undefined} cmd=$(which {banner,echo} | head -n1) until [[ "$num" =~ ^[0-9]+$ ]]; do read -p "Type a number: " num done for ((num;num>=0;num--)); do ...
5
votes
4answers
217 views

Converting `for file in` to `find` so that my script can apply recursively

I've been working on my first bash script for some time now (I just started UNIX this week). I have this idea of running a bash script to check some conditions and using ffmpeg to convert all the ...
0
votes
1answer
46 views

How can I get a shell script to change directory for me? [duplicate]

here is a small test I ran, to try and move me back to root: #!/bin/bash pwd cd / pwd It returns the current working directory, and then the correct new one, but when the script finished executing, ...
-2
votes
0answers
29 views

Unix KSH/Bash : Diff files for selected fields/columnwise only {GNU Bash 4.2 Environment}

I have two files: F1: abc|abc|abc|abc|abc| abc|abc|abc|abc|abc| abc|abc|abc|abc|abc| F2 abc|abc|abc|abc|abc| bcd|bcd|bcd|bcd|bcd| My questions are as follows: Suppose both files will have same ...
1
vote
4answers
35 views

Anyway to pass a variable to bc, having a command to be executed?

I need to pass certain variable to bc to get the output in floating point, var1=$((<some operation>)) var2=$((<some operation>)) #Needs var1 var3=$((<some operation>)) ...
-3
votes
0answers
22 views

Write a script that will send the following information to the [on hold]

Write a script that will send the following information to the screen, in the following format: Month Sales ===== ==== January 200 February 300 March 200 April 200 May ...
1
vote
2answers
72 views

One-Liner needed: Stop httpd if running already & Start httpd if not running

As part of a provisioning script for CentOS 7 I am in need to have a one-liner that performs the following. Unfortunately, I have no clue how to achieve that. If httpd is running then stop it If ...
0
votes
1answer
65 views

How to get rid of “\r” a the end of the line comming from pipeline in bash

#!/bin/bash sourcenode=$1 destnode=$2 path1=/root/test ssh root@"${sourcenode}" -t "echo "${path1}" | xargs -IDIR find DIR " | while read line do ssh root@"${sourcenode}" -t "stat -c "%a" ...
3
votes
2answers
26 views

locally created alias not being used if called using backticks (`)

I have come across this issue while trying to build up a script to do grep on multiple files for 10 different word. The script I created, is (minified) #!bin/bash alias grep='grep -n' out=`grep word ...
0
votes
1answer
33 views

find all directories (except `encoded`) in the working dir then delete all of them

I am trying to test this scenario, I have these files /encoded encode <~~~ a bash script /dir1 /dir2 .../dir2-sub test.meta what I wish is, for find to search for all directories in our current ...
0
votes
1answer
49 views

killing a job running in the background

I have started running a long job by creating a script that executes several commands on 20 or so datasets sequentially. I began in the xterm window with $ script.scr then typed <ctrl-Z> ...
0
votes
0answers
21 views

Extract table name , user and timestamp from a hive ddl statement in unix [on hold]

I am generating list of ddl statements from a hive database in a file (say out.txt). From out.txt i need to extract some information by reading each and every DDL. For example: [gand@grid1 ~]$ cat ...
0
votes
2answers
22 views

IPtables errors

I am working on a project. I am trying to write iptables rules to control network traffic. I have written some rules. When I try to apply them to the boxes that I am working on I either get locked ...
0
votes
1answer
34 views

how to write a shell script to run multiple programs

I want to run two programs ssh -f mike@c15-0330-02 'cd /home && nohup Rscript L_1.R> L_1_sh.txt ' AND ssh -f mike@c15-0330-03 'cd /home && nohup Rscript L_2.R> L_2_sh.txt ' I ...
1
vote
1answer
35 views

If statement in shell-script only half-working

I've been trying to write a script to rotate my monitor, I'll then assign it to a keyboard key. I've been fairly successful in making it rotate once, however when I run the script again, it doesn't ...
10
votes
5answers
534 views

Convert underscore to PascalCase, ie UpperCamelCase

If I have a string that looks like this: "this_is_the_string" Inside bash script, I would like to convert it to PascalCase, ie UpperCamelCase to look like this: "ThisIsTheString" I found that ...
3
votes
2answers
74 views

using the variable “file” obtained from `for “file” in` and pass to another script fails [on hold]

I am trying search for all .mkv files in my current folder, then using mediainfo I want to put the height from its meta data to a variable, but it seems it is failing. This snippet: ...
0
votes
1answer
21 views

Nnumber of HTML redirects from cURL

My little script extracts DOI's from a csv files in order to check whether they are right. The number should equal 3, and if it doesn't, I want to output an message. #!/bin/bash ...
2
votes
5answers
370 views

Problems when trying to execute sh file from another sh file

I have the following script: #!/bin/bash if test -f "/path/pycharm.sh"; then sh ./pycharm.sh; fi I am trying to run pycharm.sh from a bash file and I've looked carefully to give all the ...
0
votes
1answer
37 views

grep two searched words

I could search lines that contain two specific words using the following in multiple files: for f in $(ls *.txt); do echo ">"$f; more $f | grep word1 | grep word2 done Now, I want to write a ...
2
votes
2answers
81 views

Passing a bash command line arguments containing #

I am trying to pass pound sign as a command line argument then echoing the argument. When I pass for example 2 # 2 then I echo $1 $2 $3, I assume the terminal will output 2 # 2 but it outputs just 2. ...
3
votes
3answers
101 views

Bash script command line argument to upper case

If I can do this in my bash shell: $ STRING="A String" $ echo ${STRING^^} A STRING How can I change my command line argument to upper case? I tried: GUARD=${1^^} This line produces Bad ...
0
votes
2answers
31 views

Auto Delete Inactive files after x

Is there a way I could delete certain folders after x amount of days of inactivity? I was thinking of using cron but that wouldn't take the inactivity part into consideration. Is there any Debian ...
1
vote
2answers
40 views

I cannot understand bash script results

Here is the script: echo '1 2 3 4 5 6' | while read a b c ;do echo result: $c $b $a; done The result is 3 4 5 6 2 1 Can someone explain why?
0
votes
0answers
14 views

check media resolution if resolution is big ffmpeg it, if output is smaller than original delete the original else delete the output

I have my storage VPS filled with videos, and hoping I can free up some space, their resolution is pretty big so I decided to re encode them with ffmpeg to a smaller resolution, I am doing every thing ...
0
votes
1answer
27 views

How to terminate cat command within a shell script

I wrote a shell script that uses cat and tr commands to generate a file. My shell script looks like #!/bin/bash printf "generating random file > plaintext \n" cat -v | tr "a-z" "b-y" < ...
1
vote
3answers
90 views

Bash long string, no word splitting?

I want to tidy up some script with long commands, so that for example: { somecheck || somecomand "reallyreallyreallyreallyreallyreallylongstring" } &> /dev/null & becomes something like: ...
1
vote
2answers
55 views

How do I make a BASH loop

I'm very new to bash and Linux and I was wondering how I could make a bash loop so that when it runs, it will ask you how many times to run, and it will run that many times. I did it in LUA but I ...
0
votes
0answers
40 views

Counting program fails in arithmetic test

having a little trouble with this rather basic script. This script works on Bash in my macbook pro, but not on my Linux Mint desktop, which also uses bash. I can't figure out what's wrong with it, ...
2
votes
3answers
192 views

How to find a specific 'string' and print out the whole line?

I have a file named myfile.csv containing the following: abc:123:myname:1231 def:423324:arbitrary:value:string StackExchange:Unix:Linux From the terminal I run ./myscript.sh def The contents of ...
0
votes
0answers
36 views

Why extra space append when redirect output in a file? [closed]

I am writing one script where I search the new created files and removed files from a list of path, and store them into a file. I redirect the output the difference of two files into another file. For ...
1
vote
2answers
58 views

Using command substitution

The shell variable number contains 1 1 1 1 1 separated by tabs. I want it to contain only the first 1. I'm trying number= $(echo "$number"| cut -f 3 ) and I get the error "1: ...
2
votes
3answers
69 views

How do I remove the extra 'garbage' from this logfile?

I'm having some issues with log files from IIS 8.5 which I want to process with AWstats. Since my IIS servers are behind a load balancer I had to add a custom logging field, X-FORWARDED-FOR. However, ...
1
vote
1answer
76 views

Sed command that would ignore any commented match

I'm trying to create a sed command using regex in order to substitute something in a text file only if it is not commented but I'm running into some troubles due to my almost non-existent knowledge of ...
0
votes
0answers
21 views

Export data from Oracle to Excel [closed]

I would like to export data from oracle database on daily basis to excel sheet. I would also like to add a date condition in shell script, with which I can have data for different dates in different ...
-1
votes
1answer
21 views

How to make a process wait in the background and be able to be killed by signal other than KILL

I want a script run in the background, take some actions for every hour. It should also quit if receiving a signal. And at last, it should perform some clean-up actions before quitting. Based on the ...
1
vote
2answers
29 views

Background processes mix up order of shell script execution

Can someone explain me why the script echo one && echo two & echo three && echo four gives me [1] 3692 three four one two [1]+ Done echo one && ...
-4
votes
0answers
27 views

backup script to copy files in multiple di

Below script will list keyword from check.conf and search for those keyword in app dir. If match keyword file is found then it copies that file from App to /Data10 location. I have multiple dir's, ...
0
votes
0answers
22 views

Is there a way to add a timestamp to the logs for qsub job?

I'm submitting jobs on a cluster via qsub but the error/output logs don't have a timestamp, making debugging more difficult. Is there a way to add timestamps to the logs in the bash script? Appreciate ...
0
votes
3answers
74 views

How do I copy the latest file from one directory to another?

I have 3 zip files in a directory. I want to copy the most recent version to a backup directory. My code works fine for .sh and other files, but not for .zip. Is there something else I have to do? ...
13
votes
9answers
456 views

Filter or pipe certain sections of a file

I have an input file with some sections the are demarcated with start and end tags, for example: line A line B @@inline-code-start line X line Y line Z @@inline-code-end line C line D I want to ...
0
votes
0answers
24 views

How to write shell script on shared application on one server to pickup specific customer PID for command processing? [closed]

I have a script which runs on a dedicated environment and processed the running PID to generate heap dumps. The problem I am having is on a shared environment where there are different customers ...