Shell Scripting

10K

Solutions

6K

Contributors

The term 'shell' refers to a general class of text-based command interpreters most often associated with the UNIX and Linux operating systems. Popular shells include Bourne, Debian Almquist (dash), Korn (ksh), Bourne Again (bash) and the C shell family (csh). Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin on Windows and emulate a full Unix environment with complete shell capabilities. Terminal emulators, such as xterm, GNOME Terminal and OS X Terminal, can be used to access shell.

Share tech news, updates, or what's on your mind.

Sign up to Post

I am, at best, a novice user when it comes to writing Powershell scripts, so any simplified explanation to this question would be appreciated.
I am accessing one of our vendors API services. In order to access it, I need to generate an authentication token. I have the url to send the request to, and I have the username and password. What I am not sure of, is how to write the script to retrieve the token. Is there a "generic" method to do this?

Again, feel free to break it down to the most basic of terms. I won't be offended. :)

Thank you in advance.
0
Exploring SharePoint 2016
LVL 12
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Batch file to ping all network hosts to determinate witch are powered up and store output to a text file

Hello, I need to write a Batch file to ping all network hosts (readed from a hostslist.txt) and write UP/DOWN state to a text file.
0
how to configure aws configure in docker file

my docker file

FROM ubuntu


RUN apt-get update && apt-get install -y awscli


cmd docker pull mariadb
cmd  docker pull mysql
CMD ["/test.sh"]

test.sh
 aws configure set aws_access_key_id default_access_key xxxxxx
 aws configure set aws_secret_access_key default_secret_key xxxxxx
aws configure set default.region us-west-2
 
aws s3 cp s3://mariadbs3bucket/test.txt /test

 mysql -u xxx-pxxx --host xxx -P 3306  --socket=TCP/IP  -e "USE myDB; insert into myDB.tt values(50000);"

the above both command are working fine while running in ec command line
there i have set the aws configure
0
data no align after i do cat in unix this is my script
cat data*.txt|grep -v ^UNIT_CDE|awk '{print $1,",",$2,",",$3,","$4,",",$5,",",$6,",",$7,",",$8,",",$9,","$10,",",$11,",",$12,",",$13,",",$14,",",$15,","$16,",",$17,",",$18,",",$19,",",$20}' >>  mergetstneg.txt
catfileimg.jpg
0
I need to write a shell script to login to 5 linux servers using ssh and run a command remotely.

ssh keys are already.  key less authentication is setup already.
0
See: https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond


-h
Is symbolic link, bash convention.
See -l.


-l
Is symbolic link.
Treats the TestString as a pathname and tests whether or not it exists, and is a symbolic link. May also use the bash convention of -L or -h if there's a possibility of confusion such as when using the -lt or -le tests.


-L
Is symbolic link, bash convention.
See -l

What are the differences between these three?

"-h" has "bash concention" and "-l" not. But what is the difference in practise? Can someone give me an example of the difference?

And why it's "-L" and not "-H"? "-L" is about the bash convention, but "-l" not. However, "-h" is. So then I would expect "-H" instead of "-L".

I don't need it for something right now, but I'm trying to understand the Apache documentation.
0
Hello,

I need to run this command in a multiple linux server :

id -u user2 &>/dev/null || useradd -c "SSH account" -d /home/tools user2; echo 'password2' | passwd user2 --stdin

The idea is to create a text file with some IPs one per line and running the above command for each IP

But in somes linux servers, I can directly login as root@ip without password, but others linux servers I need to log as specific user@ip with password and switch to root

Any idea to do that ?
0
I want to write a init script to stop and start the MongoDB.
0
when i start the application using a specific command, its does spawn a process however a i am not getting the prompt back.  I have been told you to press CTRL+C to get the prompt.

This is usual behavior for starting the application.

How do i get the prompt back using the shell script?

[root@myserver]# bash -x /etc/init.d/app start
....
output omitted

^C
Session terminated, killing shell... ...killed.


when i run #ps -ef | grep app, i noticed the process is running. when i talk to the app support, they said its normal behavior.  Not sure why this happens.
0
I am working on script where i have to create a init script to start/stop the application. However the application does not stop properly. i had to kill 3 - 4 process by grepping the PID ids.

How can i do this?
0
Exploring ASP.NET Core: Fundamentals
LVL 12
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

I want to know how can I start a script at the system startup. I tried to make a sh file under /etc/rc.d/rc3.d/ but I rebooted the Os and it does not start my script as I want. :(.

Regards,
0
Morning all, I'm looking for some code that will enable IE and Chrome to go fullscreen when the web page opens. We have a number of browsers, so a single bit of code would be great.

I've added the current code I have.

What would be the best method to achieve this?

Many thanks

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Edward</title>
</head>
<body bgcolor="#000000">
<!--url's used in the movie-->
<!--text used in the movie-->
<!--
:
Min
Sec
-->
<!-- saved from url=(0013)about:internet -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="1280" height="1024" id="Edward" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="Edward.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="Edward.swf" quality="high" bgcolor="#000000" width="1280" height="1024" name="Edward" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</body>
</html>

Open in new window

0
simple Shell script to start a tom cat server (JVM) and if for some reason if server does not start within 3 mins exit and  also find any hung jvm tomcat start commands fired and force kill it.
0
Hello,
Im trying to translate this code from https://securionpay.com/docs/api#checkout-request-sign.
EXAMPLE SIGNING


export checkout_request='{"charge":{"amount":499,"currency":"EUR"}}'
export signature=`echo -n "$checkout_request" | openssl dgst -sha256 -hmac 'pr_test_tXHm9qV9qV9bjIRHcQr9PLPa' | sed 's/^.* //'`
echo -n "$signature|$checkout_request" | base64
        

EXAMPLE SIGNED CHECKOUT REQUEST


Y2Y5Y2UyZDgzMzFjNTMxZjgzODlhNjE2YTE4Zjk1NzhjMTM0Yjc4NGRhYjVjYjdlNGI1OTY0ZTc3OTBmMTczY3x7ImNoYXJnZSI6eyJhbW91bnQiOjQ5OSwiY3VycmVuY3kiOiJFVVIifX0=
				

Open in new window


to Ruby on Rails

I ended with

       
 checkout_request='{"charge":{"amount":5,"currency":"EUR","capture":true}}'
 secret_key = 'sk_test'
 @signature = Base64.urlsafe_encode64(OpenSSL::HMAC.hexdigest('sha256', checkout_request, secret_key) + "|" + checkout_request)

Open in new window


which isn't valid and its not exacly translation of the script.

When i test shell version with my secret key it works.
I tried Base64.urlsafe_encode64, encode64, strict_encode65, I tried digest instead of hexdigest. All kinds of way because I desperatly can't make it work. I think its about checkout_request data because it translates to this
 
2.5.0 :001 > '{"charge":{"amount":5,"currency":"EUR","capture":true}}'
 => "{\"charge\":{\"amount\":5,\"currency\":\"EUR\",\"capture\":true}}" 

Open in new window

and therefore signature is created with `\` before quote

question on stackoverflow: https://stackoverflow.com/questions/51506282/json-and-generating-signature
0
Looking for a script to bulk disable UAC and reboot remote servers so we can run remote installs. Looking at powershell as one scripting method since available on servers. Can look at also ding WMI.  Just any solution would be great better than doing it manual for each one. The good news we are admins on all the servers.
0
I've tried to Google this, but I guess I'm just not using the right terminology as I can't come up with an answer.

I'm looking for a way (command line, powershell, vbs script, group policy) that will make one of the icons in the notification area always show. (I'm talking about the area to the left of the time/date, where the power, network and volume typically always show).

I'm running Windows 10 Enterprise in an AD environment.

Just to make sure I'm explaining what I'm trying to do in an automated fashion correctly, here is what I do to do it manually:

RIght click on taskbar
Click Tasbar settings
Under "Notification area" click "Select which icons appear on the taskbar
In the resulting list, find the thing I want to show up all the time, and move the slider to "On"
Close out of settings

Thanks!
0
I want to write a script for automatically restoring the database from back-upset . can you please help me to provide that in case if someone has written it .

Thanks,
Merlin.s
0
I have one access_log under main folder and have to copy that access_log under another folder where external FTP Server can able to download the log automatically.

My Question is Access_log generated in server for Whole day but we need to have only access_log for 15minutes using diff command.

Please let me know the diff command to be used for changing filename automatically everytime once the diff checked between two files.
0
Hi Experts,

I want to compare directories only on two servers, without files inside each directory.
I was hoping to get output telling me what directories are missing.

Below command works but doesn't tell that parent directory31 is missing on server1.
Is it possible to get just missing directories between two server paths without copying anything?

[sat@server directory]$ rsync -n -av --include='*/' --exclude='*' --delete /home/sat/directory/ sat@server1:/home/sat/directory/
sat@server1 password:
sending incremental file list
./
directory1/
directory1/directory2/
directory1/directory2/directory3/
directory11/
directory11/directory12/
directory11/directory12/directory13/
directory21/
directory21/directory22/
directory21/directory22/directory23/
directory31/
directory31/directory32/
directory31/directory32/directory33/
 
sent 385 bytes  received 63 bytes  179.20 bytes/sec
total size is 0  speedup is 0.00 (DRY RUN)
[sat@server directory]$

server output

[sat@server directory]$ pwd
/home/sat/directory
[sat@server directory]$
[sat@server directory]$
[sat@server directory]$ ll
total 16
drwxrwxr-x 3 sat sat 4096 Jul 12 14:32 directory1
drwxrwxr-x 3 sat sat 4096 Jul 12 14:33 directory11
drwxrwxr-x 3 sat sat 4096 Jul 12 14:33 directory21
drwxrwxr-x 3 sat sat 4096 Jul 12 14:37 directory31
[sat@server directory]$

server1 output

[sat@server1 directory]$ pwd
/home/sat/directory
[sat@server1 directory]$
[sat@server1 directory]$ ll
total…
0
Introduction to Web Design
LVL 12
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

I' am writing a shell code to email my audit file produced at solaris 5.10.

Please let me know the mailx code to send the html file content as the email body.
0
Hi Experts,
According to my work , iI have a java code which generate shell script for ftp files.
So in the code
ftp.append("cd /home/user/user output/files for June ");

Open in new window

But according to shell script , If folder name contains space, then either we need to keep complete path inside quotes or space we can replace with back slash
for eg
cd "/home/user/user output/files for June " 
or
cd /home/user/user\output/files\for\June

But in java , It is not allowing me to put both  back slash \ and " saying invalid escape sequence.
How can I resolve it?
Thanks in Advance Experts............
0
Hi Experts,

I have to write a script which first read filenames in a directory and according to the name it should run jar files.
for eg filenames are according to the month and year-----07-18-01.txt ,07-18-02.txt , 08-18-01.txt,-------- (month-year-randomnumbers.txt).

My script should read these filenames , If moth-year matches with current month-year.It should run a.jar
otherwise b.jar

Current month year ,I am giving as
date +%m-%y

Open in new window

If filename contains value of this , It should run a.jar
if not ,it should run b.jar

Could you please help me to solve it..
Thanks in Advance.
0
I was experimenting with bash file descriptors and such.  I found a function to return the first available file descriptor:
#!/bin/bash

function find_next_fd() {
    local fd=2 # start at 2 to skip stdin, stdout, stderr
    local max=$(ulimit -n) # man 1 bash
    local found=0 # a flag
    while ((++fd < max)); do
        # if the file descriptor does not exist, 
        # set found and break
        ! true <&$fd && found=$fd && break
    done 2>&- # dump the bad descriptor error
    echo fd = $fd, found = $found
    return $found
}

find_next_fd
echo $?

Open in new window


This works pretty well.  If I run with no other settings, I get 3.  After executing `exec 3>somefile`, this script returns 4.  Execute `exec 3>&-`, and I get 3 again.  I wanted to see what happens when it gets to the limit.  Instead of creating descriptors up to 1024, I just removed the "!" from the test, i.e., it would return the first used descriptor.  I was expecting "0", but was consistently receiving "10".  I added these two lines into the while loop:
        echo Checking $fd
        ls -al /proc/$$/fd

Open in new window


This is a sample return:
#> ./fd-test.sh
Checking 3
total 0
dr-x------ 2 root root  0 Jul  4 04:51 .
dr-xr-xr-x 9 root root  0 Jul  4 04:51 ..
lrwx------ 1 root root 64 Jul  4 04:51 0 -> /dev/pts/1
lrwx------ 1 root root 64 Jul  4 04:51 1 -> /dev/pts/1
lrwx------ 1 root root 64 Jul  4 04:51 10 -> /dev/pts/1
lr-x------ 1 root root 64 Jul  4 04:51 255 -> 

Open in new window

0
Mac OSX question

I have a large library of digital media. Most of it is kept "offline" but the library software I use (Plex) uses media files to build the library and so I need to use placeholder files.

Using 30 second "this file is archived" videos I can easily catalog offline movies in Plex. I "rsync" the directory structure without files and then "do cp" a placeholder into each movie directory and rename using the parent folder name.

For TV shows this isn't practical as there can be hundreds of episodes per show. I would like to know if there is a way to duplicate the folder/file structure of a tv show, with many episodes under a single folder, using the same placeholder file.

To reiterate, the ultimate goal is to take a placeholder file eg. "placeholder720p.mkv" and use this file to recreate the source directory with the same filenames. So in the end I will have a folder that looks identical to the source, but consists of this placeholder file duplicated over and over. Also, there are non-alphanumeric characters and spaces in the filenames to be duplicated.
0
Hello Experts,

Good Day...

I have a script which produces password protected  zip file in linux server..I write it using expect commands.

#!/usr/local/bin/expect -d -f
send "cd outputpath\r"
send "zip -e -rj OutputFileExtracted.zip /inputpath \r"
expect "Enter password:"
send "test\r"
set timeout 40
expect "Verify password:"
send "test\r"
set timeout 40
send"*#*"

Open in new window


But the above code is not producing any output.
When I m using the same commands (not expect commands ) in linux command prompt ,It is able to zip the files with password protected.
for eg :
cd outputpath
zip -e -rj OutputFileExtracted.zip /inputpath

Open in new window

then it asked for password
Enter password:

Open in new window

User input
Verify password:

Open in new window

again user input

Any one can tell me what is wrong with the expect commands? I tried with
spawn zip -e -rj OutputFileExtracted.zip /inputpath

Open in new window

in script..That also didnt give me output.

Thanks in Advance.
0

Shell Scripting

10K

Solutions

6K

Contributors

The term 'shell' refers to a general class of text-based command interpreters most often associated with the UNIX and Linux operating systems. Popular shells include Bourne, Debian Almquist (dash), Korn (ksh), Bourne Again (bash) and the C shell family (csh). Some view the DOS 'cmd' prompt as a minimal shell of sorts. It is also possible to install Cygwin on Windows and emulate a full Unix environment with complete shell capabilities. Terminal emulators, such as xterm, GNOME Terminal and OS X Terminal, can be used to access shell.