Tagged Questions
Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
-6
votes
0answers
39 views
I have a C# Code that needs to be converted to Unix [on hold]
I am new to Unix and I need to convert the below C# code to a Unix shell script.
Program :
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ...
1
vote
2answers
37 views
sh + how to use array in sh script in order to print all values in array
I want to use arrays in my sh script.
My target is to create an array with the values a b c and print all values in the array.
I succeeded to print each array, but I failed to print all values in ...
0
votes
3answers
44 views
bash script calling itself with different arguments
I just can not get it right.
Script takes two arguments, target and command. Valid targets are specified within an array. If target is 'all', script should iterate through all targets.
#!/bin/bash
# ...
1
vote
0answers
17 views
Creating multicast join for tcpdump captures
I want to write a linux shell script which will capture specific multicast traffic. Specific as in, I want to create a pcap file that has all the traffic for one specific multicast group/port.
Here ...
3
votes
2answers
37 views
Find out extension of executable files?
When I am building software from source on a GNU+Linux system, during the ./configure stage I frequently see the following line:
checking for suffix of executables...
How do I create such a check ...
2
votes
3answers
112 views
+50
Shell Script(bash) to add or replace the license text of .c , .h and makefiles
I'm having a set of .c , .h and makefiles in a folder, where some files contains the license text and some file doesn't have any license text.So I need a shell script where I can add license text if ...
1
vote
0answers
18 views
Displays and their relative position in a shell script
I want to get information about the displays, something like xrandr, but with more info.
I want to know their position. So if I have two or more displays connected I want to know how they are ...
2
votes
0answers
25 views
Extracting lines around keys from a file
I have a large file with around 15 million lines. The odd lines contains the keys (but not only the keys) and the even lines are the data. That is, the file is something like:
WRTZ Tyrosine
...
2
votes
1answer
58 views
Integer part from float operations without | bc
I read a billion of discussion about this but still have confused thoughts.
I just need to use bash to calculate some parameters, and for this operation I need to get the integer part of a float ...
1
vote
1answer
30 views
command not found in shell script
Please tell me why I couldn't print variable value.
# chmod 777 chkscript.sh
# ./chkscript.sh
chkscript.sh file content
variable = "This is variable"
echo "$variable"
echo "Hello World "
...
2
votes
0answers
33 views
Scripts cannot run simultaneously on startup
I want two scripts (Server_drive, Server_video_boot) running on startup, but there is conflict between them. Specifically, there is always running the script with the lower priority. I tried with many ...
2
votes
1answer
64 views
After printing the previous line where the file contains a single token now need to traverse through the result to meet the requirement
I have used the below code to print the previous line where the file contains a single token
#! /bin/ksh
file=input.txt
while read line
do
awk 'NF == 1 { print LAST } { LAST=$0 }'
done < "$file"
...
4
votes
1answer
32 views
Executing commands with ssh and shell script using variables on a remote machine
I'd like to execute a command and script located on a remote machine with a script on a local machine. I know it's possible to execute these kind of commands with ssh, so I made:
#!/bin/bash
ssh ...
5
votes
1answer
28 views
Ctrl-C is ignored by pppd when put in a shell script
I'm trying to connect to GPRS network through a serial port connected GSM modem.
When I call /usr/sbin/pppd call <peer_name> from the command line, it correctly receives and handles Ctrl+C from ...
0
votes
0answers
13 views
How to complete a script to move selective files and directories in a filesystem to another (dump) path in a different filesystem?
1) There is a filesystem, say FS1, having below files and directories :
drwx------ 2 256 Jun 20 05:47 recovery_scripts
drwx------ 2 256 Jun 20 05:47 sqllib
-rw------- 1 ...
0
votes
2answers
4k views
How to add arithmetic variables in a script
I want to accumulate the line size of a number of files contained in a folder. I have written the following script:
let a=0
let num=0
for i in folder/*
do
num=`cat $i | wc -l`
...
3
votes
1answer
38 views
Launch RDP silently?
I currently use the following command to launch an RDP session which works fine:
rds@rds:~/Downloads/FreeRDP$ xfreerdp /v:farm.company.com /d:company.com /g:rds.company.com /f /u:username /p:
At ...
2
votes
1answer
20 views
set flag to remove duplicate records from a file based on some values of the record
I have a file having the following records (pipe delimited):
SK200-10|ALBUMIN-SK|INS|SEKURE ALBUMIN 2 X ...
4
votes
1answer
33 views
Default to “Execute” when double-clicking on a shell script in PCManFM
Is it possible to get an executable to execute by default?
What I mean is this. I have an .sh file, which if I click on twice, it will show me this:
If I then click Execute, it does the right ...
3
votes
2answers
230 views
How do I run a script when I switch between keyboard layouts
I use more than one keyboard layout, and I would like to find a way to run a script when I switch between them.
Is this possible?
So far, I can assign a shortcut for a script like this:
#!/bin/bash
...
6
votes
1answer
44 views
BASH return to main function
I have a BASH script that calls a function, which calls other functions:
#!/bin/bash
function foo
{
function bar
{
# do something
}
bar
}
foo
How can I return from bar ...
0
votes
1answer
32 views
Restrict user to run shell script except which is defined in sudoer file
I have scientific linux 6.4 running on my system, I have restricted other users to run shell script except one, which is defined in /etc/sudoers file.
For example:
I have one file.sh in my admin's ...
11
votes
4answers
2k views
Is there a JavaScript shell?
Recently I've been working with JS and I'm very enthusiastic about this language. I know that there is node.js for running JS at server side, but is there a shell that uses JS as a scripting language? ...
23
votes
3answers
897 views
Should I care about unnecessary cats?
A lot of command-line utilities can take their input either from a pipe or as a filename argument. For long shell scripts, I find starting the chain off with a cat makes it more readable, especially ...
1
vote
0answers
21 views
Open to specific gvim tabs
I have a working environment that I'd like to save via a script.
-EDIT:
I don't need to save it's state, I just want my script to define it. Though saving state would work too I guess.
Currently it ...
0
votes
2answers
32 views
Using exec in find over ssh from shell script
So, I am attempting to execute the following from within a shell script;
ssh -q $CUR_HOST "cd $LOGS_DIR; echo cd $LOGS_DIR; find . -name *.log -mmin +1440 -exec gzip {} \; exit"
When this runs, it ...
2
votes
1answer
44 views
Bash script for running python virtual environment does not execute
I am trying to wrap the following call into a script, which runs my Python virtual environment:
[lucas@lucas-ThinkPad-W520]/home/lucas/bin$ source ...
0
votes
1answer
35 views
Disable Touchpad automatically at startup
I'm running Mint 17 Mate on a new HP250 laptop. I can turn off the touchpad by typing the following from terminal:
synclient TouchpadOff=1
Now I want to disable the touchpad automatically each time ...
1
vote
2answers
49 views
how to get string between braces along with string without braces using awk
My input is:
ABC_DFG_FRE
s(DFR_GHY_JUY)
BGR_KIU_PLO
s(VFR_KJU_MKJ)
output sholud be:
ABC_DFG_FRE
DFR_GHY_JUY
BGR_KIU_PLO
VFR_KJU_MKJ
0
votes
1answer
28 views
BASH paste sourced files into main source
I have a fairly large BASH project, which I split into multiple files to make it more readable. As a result, the main file contains many source statements.
Now I'm releasing it on GitHub and I'm ...
1
vote
1answer
36 views
Change a value in a config file, or add the setting if it doesn't exist?
When modifying config files from the command line, I often want to find the setting in the config file and modify that line if that setting exists. If that setting doesn't exist, I want to add it to ...
8
votes
6answers
784 views
Bash- detect init system
This may have more to do with detecting operating systems, but I specifically need the init system currently in use on the system.
Fedora 15 now uses systemd, Ubuntu uses Upstart, while others use ...
11
votes
7answers
559 views
Shortest way to extract last 3 characters of base (minus suffix) filename
I'm trying to set a variable in an sh script to the last 3 characters of the base name of a file (by base name I mean without the path and without the suffix). I've succeeded in doing this but, purely ...
1
vote
1answer
39 views
Create a log file with the same name as input file
I'm new to linux shell scripting. I have few input files that I have to parse one by one. So in my "work in progress" WIP folder I have one input file at a time. While one file is under processing I ...
2
votes
1answer
20 views
move the search content to different directory
I am on Oracle Solaris.
I am using:
grep "searchstring" filename.*
above command returns my search result.
Now I want to move the all the files in above search result (all the files not the ...
6
votes
3answers
5k views
#!/bin/bash - no such file or directory
I've created a bash script but when I try to execute it, I get
#!/bin/bash no such file or directory
I need to run the command: bash script.sh for it to work.
How can I fix this?
2
votes
1answer
374 views
KSH styling text based menu using STDERR
Is it possible to format the STDERR in order to have a better looking menu using the select command?
I have a simple select
select oChoice in $(<tempMenu.menu) ; do
case "$oChoice" in
...
4
votes
1answer
108 views
how to set environment variables from a shell script? [duplicate]
I'm trying to set environment variable through a shell script. Here is the script with various techniques:
#!/bin/sh
echo "export SOMEPATH=/root/some" >> /root/.bash_profile
echo "export ...
1
vote
1answer
47 views
Fastest way of find and replace in large file with replacing filed present in another file
I have two files. File1 is a csv with 60 fields:
111,Check1|^/h1/h2/h3,22062014184500,20,0.....
111,Check2|^/h43/h40/h9,22062014184500,4,.....
111,Check3|^/h1/h3/h4,22062014184500,0,0,.....
File2 ...
3
votes
3answers
84 views
Is there some way I can start a (repeating) ping while the network is unreachable?
My ping command (on Debian 6 or 7) will repeatedly attempt to ping a server even while the network is down, if the network was up when it was started. Is there some way to start ping while the network ...
0
votes
2answers
34 views
names that occur the largest number of times in a data set
users directory
----------------------
hjsyeh hellodir ;
awgshd newdir;
hjsyeh hidir;
jkdhjk welcomedir
the above given are set of users and the directories they created .How can I ...
2
votes
1answer
36 views
Why is the PGID of my child processes not the PID of the parent?
So I keep reading everywhere that this command should terminate all child processes of the parent process:
kill -- -$$
Using a negative ID with the kill command references a PGID and from the ...
1
vote
7answers
67 views
Get text between two special characters in a line using shell
I have a line which comes from a file via:
cat aaa.txt | grep "HIJK"
Output gives:
HIJK="My name is HIJK"
I need to get the text My name is HIJK into a variable in a shell script.
I have tried ...
0
votes
2answers
36 views
Output multiple strings out of multiple files
Hi my current code is:
find /home/user/logfilesError/ -maxdepth 1 -type f -name "gBatch_*"\
-daystart -mtime -1 -exec grep -rl "ERROR" "{}" + | xargs -l basename
if [ $? -eq 0 ]; then
...
3
votes
6answers
61 views
Collapse some repeated parts of successive lines
I have data in notepad like this:
4480-1
4480-2
4480-3
4480-15
4581-1
4581-2
4581-3
4581-4
Can we do it using for loop sort of things? With sed?
My required output is ...
0
votes
2answers
29 views
list files and store it in variables
im new with shell programming.
my goal is to give the user a selection which file should be run.
i catch all available scripts in one var with:
var=$(find script*)
so far so good.. this is the ...
1
vote
1answer
20 views
How do I obtain the kill signal / message / reason within a script?
I am using the following trap:
trap OnExit EXIT
And in my OnExit function I would like to capture all the info I can on what happened so I can write it to a log file. Id like to know who, why, how, ...
0
votes
1answer
47 views
Search a string between two timestamps starting from bottom of file
I was trying to find a string Cannot proceed: the cube has no data in huge test.txt file only between timestamps yesterday 22:30 pm to today 00:30 am.
Script:
tac test.txt | awk -v today=$(date ...
2
votes
3answers
42 views
Concatenate filename inside of CSV file for each line for multiple CSV files
I have lots of CSV files and I need the filename of each specific CSV file in every line of each file.
Original file content of abc123.csv:
ColVal_1;ColVal_2;ColVal_3
ColVal_4;ColVal_5;ColVal_6
...
0
votes
1answer
29 views
How to make xargs ping and head output as expected?
Given an array of domains I would like to obtain their IP addresses, in the following format:
98.139.183.24
98.137.236.24
This script
#!/bin/bash
domains=(yahoo.com yahoo.ca)
printf "%s\0" ...