Questions about shell scripts, executable files that are interpreted by a shell (bash, zsh, etc.).
-3
votes
0answers
22 views
New to c-shell script [on hold]
I'm learning to c-shell script as a side project and I find this language very confusing compared to the main languages such as c++ and java..
So please help me on this please..
Q: how do I create a ...
-1
votes
2answers
45 views
bash shell script two variables in for loop
for SLAVE_CLUSTER,MASTER_CLUSTER in $MASTER_CLUSTERS $SLAVE_CLUSTERS
do
echo "Master cluster boxes are ${!MASTER_CLUSTER}"
echo "Slave cluster boxes are ${!SLAVE_CLUSTER}"
done
I am ...
1
vote
1answer
37 views
How to add users to Linux through a shell script
The shell script that I have to write has to create new users and automatically assign them to groups. This is my code so far:
echo -n "Enter the username: "
read text
useradd $text
I was able to ...
0
votes
0answers
20 views
Canvas(blackboard)-like program
I have to make a program that has most of the functions those websites have and I am stuck at the point where I have to get the grades from a file and use a formula to calculate the students final ...
0
votes
2answers
40 views
Parsing a Blocked file and generating smaller files
I have a file like below:
1weather dnsndjsdn
2nm bdbdb bdbdbdbdnnd
3gfdu hsihdishdis
5
1hdohdsohsoihssodhoishs
2nfdksnkdsnfsdsjndkdj
3kjdscdskndskjndndsdsdsd
5
Like wise I might have close to ...
1
vote
1answer
24 views
Automatically run certain scripts at first login/PC startup
I have some scripts that I would like to run when OS starts up(e.g. script that connects to internet). Right now I'm doing it by running it every time I log in after PC startup. How can I make it so ...
6
votes
5answers
1k views
How to find lines containing more than 100 characters and contains “if”?
So, probably I should use grep for this. As long as I need recursive search I should use grep -r. But then I don't know what should I do next ;)
How can I do that?
1
vote
3answers
32 views
How to check for the first element in an Array
I have the following Array Loop set up. It simply loops through a string and checks to see if each item matches a letter and sets some variables accordingly.
#!/usr/bin/env bash
IN="ItemName -a -b"
...
0
votes
1answer
25 views
Output the difference between data in script
I have tried to make script which can help me to output info about received and transmitted data on specific interface.
Here is the beginning stuff of it:
#!/bin/bash
interface=$1
while true; do
ip ...
1
vote
1answer
31 views
rotate element of array in shell script
I wanted to rotate element of array in shell script
Array=(11 22 33 44 55)
i tried this
Array[0]=${Array[$3]}
but it is not working, i'm getting array as it was declared.Why?
Finally i got it ...
1
vote
1answer
45 views
Inserting variables in a command within a shell script
I'm attempting to write an automated script which will update the IP address for my Raspberry Pi within my /etc/hosts file.
I'm able to execute this line just fine,
IP=`sudo nmap -sP 10.61.4.0/24 | ...
1
vote
1answer
31 views
script to print last login in unix
I Want a to print the last login information of user in a .csv format.
I tried last and lastlog command but getting error.
Error for last:
/usr/bin/last patrol
/var/adm/wtmpx: No such file or ...
2
votes
1answer
48 views
.profile is written in shell script — can I instead make my system understand that I want it to execute a Python script instead?
I get Python. I don't get shell script. I could learn shell script, but I would rather not if I can use Python in its place.
A good place for me to start would be the .profile script. Currently, for ...
2
votes
2answers
27 views
Use of \$ at end of variable name passed to grep
I was going through one of the shell scripts and found a line :
ls $dir | grep -c "$NAME.${var}\$"
I understand that $ would expand the variables NAME and var, but is it required to put \$ at the end? ...
1
vote
1answer
27 views
Escape shell arg from one script to another
Given ./mysh0:
#!/bin/bash
exec ./mysh1 $*
And ./mysh1:
#!/bin/bash
echo $1
echo $2
echo $3
How do I call mysh0 such that the arguments to mysh1 and what's eventually printed are "A", "B 2" ...
2
votes
1answer
16 views
Parameter ignored when quoted
I have a directory with 3 files: file1, file2 and the following bash script:
#!/bin/bash
set -e
Command="ls -1 -I file1"
echo "Command: $Command"
Files=`$Command`
echo "Files:"
echo $Files
The ...
0
votes
3answers
46 views
Passing Variable from one script to another
How can I pass a variable between scripts?
Example: I have two test scripts:
-- test2.sh
#!/bin/bash
echo "this is test2.sh"
echo "varname is $varname"
echo end
-- tes1.sh
#!/bin/bash
...
1
vote
2answers
34 views
Apply SHA256 and Base64 to string in script
I'm trying to apply SHA256 and then Base64 encode a string inside a shell script. Got it working with PHP:
php -r 'echo base64_encode(hash("sha256", "asdasd", false));'. But I'm trying to get rid of ...
0
votes
2answers
30 views
Alternative to script command getting directory names (using ls & awk)
Related to my question about awk being ignored by cron, are there any alternatives to awk? This is the line in question:
for dirlist in `ls -l $WEBFOLDER | awk '$1 ~ /d/ {print $10 }' `
I don't ...
1
vote
1answer
15 views
How to see the lines whose date column is less than x day from today
My file
ID=29524 02/12/2015,23:59:34,'PAt, 0,
ID=29628 02/12/2015,23:59:37,'PAb, 1.9,
ID=30816 03/12/2015,00:00:20,'PAc, 4.15,
I would like to print files with X days less than from today.
My try ...
0
votes
1answer
25 views
how to export table data in to .csv file using shell script
I need to get the data from mysql server and export to .csv file .i need to export data to new .csv file daily automatically.
query:select count(*) count,create_date from tabpush where status=1 and ...
-2
votes
0answers
16 views
shell script to check all(may be 15) files present in a directories [on hold]
how to write an shell script for below
I have 4 directories /usr/abinah/apps/d1,user/abinash/apps/d2,user/abinash/apps/d3 and usr/abinash/apps/d4,every time 15 files ftp to each of these ...
3
votes
2answers
43 views
Content of /proc/<PID>/cmdline file depends on script shebang?
I have a bash script named test.sh which I start with startproc. In case I use #!/usr/bin/env bash shebang in test.sh, the /proc/<PID>/cmdline file looks following:
SERVER:~ # cat ...
0
votes
2answers
22 views
Creating one file from another based on search terms
How can I create a file that contains everything after and including a particular search term from another file in the terminal?
Example:
Original file content: foo, bar, baz, qux
Search term: baz
...
0
votes
0answers
14 views
Sudo access without any password prompt [duplicate]
I have set up sudoers.d file unix as below:--
User_Alias OOZIEUSERS1 = user1, user2
Runas_Alias APP1 = oozie
Cmnd_Alias SU_APP1 = /bin/su - oozie
OOZIEUSERS1 ALL = (root) SU_APP1
...
7
votes
1answer
167 views
Bash script parsing argument with quotes
Please consider this simple script named test:
#!/bin/bash
echo $1
and the following commands and calls:
$ echo "A B"
A B
$ echo ""A B""
A B
$ echo """A B"""
A B
$ echo """A B"""
A B
$ ./test "A ...
-2
votes
0answers
17 views
How to compare below output where i should get which is having greater value
Input is below
Input value :
FamousDocs 2
FamousDocs 3
Output : Compare both lines and which is greater value that should be printed ..
0
votes
0answers
27 views
sed problems rip text out within a string and ridding it keeping what's left - [on hold]
I got this off here or somewhere within InterNet Land. I could swear that it worked before. now I am puzzled cuz it seems to not work, now. ( the sed code)
the general set up is: I get the file name ...
0
votes
1answer
39 views
Bash to clear historic content folders
I require a bash script to keep the most recent 'date_YYYY-MM-DD_HHMMSS' directory, removing others
The directory structure is as follows. The directories in tags are variable and will change, i.e ...
2
votes
1answer
77 views
Iterate over bash array
I want to use the values of one array to point to values in another, but I can't figure it out. I think this is very basic. I'd like the file to yield one line associated with each of x, y, z as ...
2
votes
2answers
36 views
How to stop bash scripts from exit ing the window altogether
When I write bash script and I have
exit;;
or
exit 0;;
the script not only exits but the window (or pane in the case of tmux panes) exits completely (goes away).
e.g.
while true; do
read -p ...
2
votes
2answers
46 views
Bash script to insert information after each line of block of data
I wish to write a script that would insert information from the /proc file system to a list of processes generated by top. It would be something like this:
Here is the sample output that I get from ...
0
votes
1answer
28 views
Idiomatic bash way to run optional action without side effects on exit code
This script will exit with test result which is not desired from callers perspective. How it should be implemented instead?
#!/bin/bash
test -n "" && echo "test passed"
-1
votes
1answer
17 views
How does the shell script variable, that holds a command, work? [on hold]
I'm trying to create an auto-compiling script that will compile programs from source, whenever I boot up my computer. It currently goes roughly like this (I can't remember the exact syntax):
...
1
vote
0answers
30 views
Print Dialogue configuration to command line
I need help figuring out which program gets called with what all arguments when I print a file using the standard print dialogue with a specific configuration, so I can automate it using a script.
...
-2
votes
1answer
40 views
Finding lines with multiple entries and give specific word of line back?
I have the following file with a list of marathon runners:
# key: sex, time, athlete, athlete's nationality, date, city, country
M, 2:30:57.6, Harry Payne, GBR, 1929-07-05, Stamford Bridge, England
...
-2
votes
0answers
24 views
I have a script that calls another scrip that needs to be exited via a keypress
I was told by someone else where that I should open another thread in order to get this inquiry addressed. I have a script that executes another script on 5 second intervals. My question is If I run ...
-4
votes
0answers
48 views
Shell Command for a list of names [on hold]
I have a list of names with dates, locations etc.
For example:
M, time, FirstName LastName, date, location.
And now, I would like to exclude everyone with more than a first and a last Name, for ...
1
vote
1answer
15 views
Why won't this example of setUID work? [duplicate]
I am learning about setuid and setgid where the user executing the script will inherit the owner's permission while running the script. To test this,
I created a bash as user fiverr in ...
1
vote
0answers
20 views
/bin/csh Event not found ? C-shell
I know this question has and does come up a lot (I know because I pounded Google to death and often came back here from the redirects).
Below is my script. I'm not entirely certain what I am missing, ...
1
vote
4answers
25 views
How to extract lines starting with a certain letter?
I have a texfile with a many lines in it, Example lines:
AABBA, 10050, Tom marc Peter , POR
BBBAC, 10051, Eva braun, AUS
CCAHA, 10052, Jon murry , UDD
GGHAN, 10053, Taler yon, AGG
IIUSA, 10054, Raff ...
1
vote
1answer
22 views
clear command in console dialog
My bash script contains the clear command, that when executed through dialog command will result with strange letters.
How can I still use clear command without seeing this output in the dialog?
This ...
1
vote
1answer
21 views
Exiting a running script with any button
I have a script in which I'm trying to add the functionality of exiting upon keypress. Thus far, my code looks like what you see below:
keyinput=''
if [ -t 0 ]; then stty -echo -icanon -icrnl time 0 ...
0
votes
2answers
36 views
for loop in bash
I want to create a for loop that runs from 1 to a number stored in a variable. But it produces this error:
Syntax error: Bad for loop variable
This is my script:
#!/bin/bash
count_lines ()
{
...
0
votes
0answers
16 views
Create symbolic link recursively, if file 1.JPG exists rename it to 1A.JPG
I have got a shell script for creating symoblic links of all my photos of a year. The photos are from different cameras and in subdirectories.
f=$(pwd);
export f;
q="2015/";
z="2015_Links/";
find ...
-1
votes
2answers
23 views
Nested echo command in backticks
I want to know why an extra echo will print in my shell. I'm using bash version 4.2.46(1).
echo `echo `echo $SHELL``
A interesting issue is if I replace '``' with $() it doesn't print extra echo:
...
-3
votes
1answer
30 views
How connect to another file and use its elements [closed]
I have a file hello.txt containing 8 columns. My job is to create directories such that their names correspond to the first 4 characters of the 1st column inhello.txt.
So far I have done
...
13
votes
3answers
759 views
How to get HOME, given USER?
I have an USER variable in my script, and I want to see his HOME path based on the USER variable. How can I do that?
1
vote
1answer
42 views
Record cpu% reading in period
My question is let the user determine the period of recording down the CPU%
reading and my code is like this
#!/bin/bash
watch -n $1 ps -eo pcpu
it's correct or not?$1 is an argument.
2
votes
2answers
31 views
How to check if directory is mounted on disc X and mount it if it isn't
I'm trying to write script to back my data up. I don't know much about it, so I might take a wrong approach, but what I'm trying to do is use rsync -avh several times for each directory I want to back ...