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

learn more… | top users | synonyms (2)

0
votes
2answers
40 views

How to use file test to check if a file already exists in a directory

I'm trying to write a script that asks the user if they are sure they want to move a file to a certain directory. The script needs to check if the file already exists in the target directory and if it ...
4
votes
2answers
72 views

Millisecond time in a shell script

How can someone print the entire time ie, for example 12:07:59:393(HH:MM:SS:milliseconds) in milliseconds. I found a lot of posts saying how to print Milliseconds along witht HHMMSS but I want to ...
3
votes
3answers
83 views

How to prevent script from deleting itself

Hi I'm creating a recycle bin script with the command name 'safe_rm'. I was wondering, how can I prevent the script from deleting its own file. I believe the readlink command is one solution however ...
-1
votes
0answers
27 views

Python to Shell Script? [migrated]

How can I convert this simple python code to Shell script? import time import sys cur_time = int(time.time()*1000) print cur_time sys.exit(1)
3
votes
3answers
220 views

Bash replace characters in the output

I need to replace characters in the output of a script but they are NOT in the last printed line. They are in the middle of the output. E.g. ...
0
votes
1answer
56 views

Need help on shell scripting

I need a help on my shell script. Below is my shell script which transfers the file from one server to another. #!/bin/bash echo "Please enter id no : " read input_variable echo "You entered: ...
-1
votes
0answers
38 views

How to compare two tables in Linux using shell scripting? [duplicate]

I have two database one is "old-tables" and one is "new-tables". We have made some changes in "old-tables" database. then updated "old-tables" database we are calling it "new-tables" database. ...
-1
votes
2answers
90 views

How to compare two tables and find the difference between in Linux using shell script?

I have to compare two MySql database data, I want to compare two MySql schema and find out the difference between both schema. I have created two variables Old_Release_DB and New_Release_DB. In ...
1
vote
1answer
40 views

bash script does not compare file names with [ and ] correctly

I have a bash script that deals with files. It finds all the files in one directory and searches for the name of each in another directory. For that it uses "${myfiletobesearched}" inside the ...
1
vote
1answer
78 views

Pattern matching [duplicate]

I am trying to follow Bash Cookbook to learn about Bash Scripting. I am on example 6.8 Testing with Regular Expression. I have the following script: #!/usr/bin/env bash # cookbook filename: ...
1
vote
1answer
23 views

mv command with path wildcard containing random string

Im trying to move a file to a path which has a random string that I cannot know in advance ~/.config/foldername/45fhiu84.dev-edition/subfolder/ I have tried mv ~/Downloads/myfile.txt ...
0
votes
1answer
33 views

Can all of fork(), exec() and system() be wrong? [closed]

I understand why it could be less than best practice if I write C code that executes shell commands by calling system() and that it's better to use exec and fork but then a very experienced C ...
0
votes
2answers
41 views

Can we install a package through a shell script? [duplicate]

I'm trying to write a shell script so that when I reinstall my Ubuntu again. I could just run script and retain all the packages. And I'm planning to pass password in form of argument. My question ...
0
votes
1answer
38 views

Script for connection with ssh then command once connected

I need to write a script that connects to a remote server, then once connected, connects from there to another server, then changes directory. The following of course does not work (it connects to ...
-3
votes
0answers
20 views

Bash Script problem with Variables from files [duplicate]

Trying to get this script to work how ever I get an error no matter how I try to set the varibles. After checking the varibles are not being set from the files that the information is in.
-4
votes
2answers
33 views

Linux Bash script fails with a syntax error

Trying to get this bash script to work: #!/bin/bash for result in $(cat ./fn7); for dip1 in $(cat ./fn4); for dip2 in $(cat ./fn5); for dip3 in $(cat ./fn6); for ip in $(seq 0 255); ifconfig > ...
2
votes
3answers
84 views

Replace values in file

I have a files: $cat file1.txt 1234|W 1345|S 8427|D 2132|C 3243|V and my sql file is : $cat select.sql SELECT * FROM CUSTOMERS WHERE ID IN (FLAG); and I have a shell with the next ...
0
votes
0answers
22 views

I'm able Start Service With init.d script, however doing service <service name> start does not work

I'm able to start a service with an init.d script, however doing service <service name> start does not work. For e.g. /etc/init.d/haskal start, the service is starting fine and service haskal ...
3
votes
1answer
52 views

Create table with frequency of unique names retrieved from multiple .csv files

I have 32 CSV files containing fetched information from a database. I need to make a frequency table in TSV/CSV format, where the names of the rows are the name of each file, and the names of the ...
0
votes
1answer
20 views

shellscript is having trouble finding a file [duplicate]

I have a shellscript that is having trouble finding a file. The text file exists so I don't understand what the issue is. #!/bin/ksh goodmain $1 | sed -e '1,/mmxxaa/d' $ ls -l total 1364 ...
0
votes
1answer
53 views

Running .sh Script With Sudo Results In Different Output

I'm seeing some really strange behavior in a script I'm working on.What I have is an svn hook that gets run whenever a commit is made to an svn repo. It runs a sqsh command that generates another ...
0
votes
2answers
50 views

How to fix vmware header error?

I'm trying to run vmware on my kali linux 2.0 box, because I want a lab to practice my skills on, but vmware won't launch it's giving my an error message saying "C header files matching your running ...
0
votes
1answer
38 views

If else statement involving two numbers in scientific notation [duplicate]

I have two numbers in scientific notation and I want to do some comparison between them in an if statement in bash. While doing so, I am getting error like bwlow: E.g: bash-4.2$ a=10e-12 bash-4.2$ ...
0
votes
1answer
40 views

Script too slow ? Any particular reason?

I have a script which does hexdump along with pipeline commands and finally I am redirecting it to a file. Now I am logging data from the serial port of my Raspberry Pi. I also call a python ...
0
votes
1answer
34 views

command /opt/bin/date --date '-15 minutes 2016-04-27T14:14:47' producing result many hours before stated time

I'm using the following command in an attempt to work out the time 15 minutes before the timestamp: /opt/bin/date --date "-15 minutes 2016-04-28T16:58:55" '+%Y-%m-%dT%H:%I:%S' The problem is the ...
2
votes
4answers
47 views

How to catch and handle nonzero exit status within a Bash function?

Say I have the following (pointless) Bash function: myfunc() { ls failfailfail uptime } I run it as follows: myfunc || echo "Something is wrong." What I want to happen is ls runs (as ...
0
votes
1answer
28 views

Correct syntax for inputting date variable into date calculation code

In my script, the following code successfully produces a timestamp variable for $n in the format 2016-04-28T15:47:48 for n in $(perl parsetime.pl | sed "s/.....$//") do echo $n result is: ...
1
vote
1answer
63 views

Escape strings to be posted via curl

I am trying to make a script that takes some atom feeds and posts them to slack through the Slack API via curl. What I have now works for simple texts, but some of them have double quotes or & ...
1
vote
3answers
56 views

how can we use multiple variables in single for loop in shell script?

I am implementing as below code using for loop but wrong output coming after running the script. for i in `awk -F"|" '{print $1}' $INPUTFILE`, j in `awk -F"|" '{print $2}' $INPUTFILE` do echo $i:$j ...
1
vote
2answers
37 views

loop create from file

I have a file(test) It contains two columns and two lines pippo mm pluto tt I would like to create directory,owner and create password I do some think like that while IFS= read a b; do mkdir ...
2
votes
1answer
38 views

How do I check for the existence of a process without a failed exit code being returned?

I’m using Amazon Linux. I want to start a process provided one isn’t running already. This is a bash script I embed within a Jenkins Maven job. So I have pids=$(pidof /usr/bin/Xvfb) if [ ! -n ...
0
votes
1answer
36 views

unzip without replacing original file and report to log

I want to write a bash script to decompress a file without overwriting the original one and redirect the operation result into a log file. I found an answer to the first part of my question at: How ...
1
vote
1answer
37 views

cannot get screen command to execute code containing DISPLAY=:0

I am trying to ssh into a remote machine and run a shell script, which opens a GUI. I want the GUI to open on the remote machine and remain open (so I am using DISPLAY=:0 nohup). I tried: ssh -t ...
0
votes
1answer
22 views

Dynamically write bash script from another?

I am trying to dynamically create and write to a file a bash script from from a current bash script. echo "## Get the IP of the system that was assigned #!/bin/bash ip=$( hostname -i | xargs ) echo ...
0
votes
1answer
21 views

Including milliseconds in a Script?

sudo hexdump -v -e '1/1 "%02x\n"' /dev/ttyUSB0 | awk '$1=="ed" { getline byte1 getline byte2 number = strtonum("0x" substr(byte2,2,1))+2 ...
0
votes
1answer
16 views

Setting XDG_CACHE_HOME Breaks Firefox Installation

In my .bashrc I set my XDG_CACHE_HOME variable to "~/.cache/". This breaks my Firefox installation, telling me that it cannot load my profile. Without this line, Firefox loads properly. I have ...
0
votes
1answer
21 views

printf in my output now

The encryption on this problem just got more interesting. I started with this script: while read CTFlist; do #next we need to create ctfs padded with zeros as a variable ctfPadded=(printf ...
-1
votes
1answer
56 views

add multiple .csv files using bash command

I want to iterate over all randomly generated CSV files in a folder using using bash and add them line by line. Each CSV files has 3 rows, the 1st row indicates just the number of generated files and ...
-1
votes
2answers
43 views

Use of && and || operators to handle the result of the same command

In bash, is it possible to use these two operators to handle both of the exit statuses of the same command ? or if I want to handle both cases, I have to use an if statement ?
0
votes
3answers
49 views

sed substitution

I have a string as follows: /test/test/ 12 /test/test My goal is to turn it into: /test/est/ 12 /test/test This is the command: echo "$x" | sed 's@\(/*/\).@\1@g'" I am using at the moment but ...
2
votes
2answers
315 views

How can I redirect the output of a child process?

I am running the following git clone command through sudo and bash and I want to redirect STDOUT to a log file: % sudo -u test_user bash -c "git clone https://github.com/scrooloose/nerdtree.git ...
0
votes
1answer
34 views

getting links including outer html

From a html page with lots of links, I'm looking for a way to extract only the links that follow a specific format. <a href="https://always/same/link/same-name_19.html">always same ...
0
votes
2answers
47 views

Binding Timestamp with Hexdump?

I am running a script which is given below, sudo hexdump -v -e '1/1 "%02x\n"' /dev/ttyUSB0 | Many Pipes | gawk '{ print strftime(":: %s"), $0 }' Here the data is being hex dumped with timestamp ...
0
votes
3answers
44 views

BASH: pass arguments to sub-script

I have a script like this: #!/bin/bash . config ./sub-script There are a lot of variables in config and I don't want to pass them to sub-scirpt like ./subscript arg1 arg2 ... arg100500. Also, I ...
0
votes
0answers
32 views

How can I create a script to do not mount pendrives for some time?

I'm new to Linux (I'm using Ubuntu 14.04) and I want to create a script to deny pendrive mounting. What I want: root user deny pendrive mounting to everybody except him for 4 hours. More: how to ...
0
votes
5answers
71 views

Adding time stamp to a log file?

I am running a script file. I have written a while loop inside the script in which I have pipelined multiple commands like awk, sed and finally I am writing the output to a file using > operator. I ...
0
votes
1answer
33 views

Bash script using mysql command with variables failing

I have a script to clone a vhost and associated db - however one of the mysql commands doesn't work. It fails and ends up outputting the mysql version number and 'how to use' info as if it hasn't been ...
-2
votes
2answers
65 views

standard deviation using awk [closed]

I am using below command to get standard deviation of file A names 1 2 3 avg 23.3107 20.0372 21.7236 21.6905 awk '{x[NR]=$0 ;} END{a=$4; for (i in x){ss += ...
1
vote
1answer
47 views

Creating a complex variable content by hand

I am creating a shell script dynamically and sending it to a remote server for execution. All is working except when I try to inject a variable with content coming from a file with multiple lines, ...
0
votes
6answers
100 views

how to do formatting of a file in unix

I have a file file.txt. which have below three records. <ResultDescxmlns="http://www.mpaet.com/boe/interface/common">Operation successful. 220095 9251000014 Now my desired format should be as ...