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

When i execute this cURL command from my linux ubuntu CLI it executes as a GET instead of a POST request. What am i doing wrong here? I cant figure it out and its driving me insane!

Also this WORKS in postman, but when i run the exact cURL shell from postman i get a 400 from the API, the vendor is unable to specify what the issue is.

curl 
-v 
-POST
 -H 'Accept: */*'
 -H 'Accept-Encoding: gzip,deflate' 
-H 'Cache-Control: no-cache' 
-H 'Host: api.mapbox.com'
 -H 'content-type: multipart/form-data; boundary=——WebKitFormBoundary7MA4YWxkTrZu0gW'
 -form file=@/home/matt/test.geojson.ld 
--url 'https://api.mapbox.com/tilesets/v1/sources/achuhealth/mack-testing1?access_token=TOKEN'

Open in new window

0
Exploring SharePoint 2016
LVL 13
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.

Hi Experts,

I've been working on this powershell script and need some help with a couple of things.  The script will be called from this vbscript to pass the computername or listofcomputers variables.

What I'd like expertise or help with is:

1. I've tested calling this from the VBScript Code in top comments section, but didn't get the computername variable to pass down.  (this would be done from the vbscript above, but wanted just a test wrapper to test).  EDIT:  If this is too difficult, I'd like to set it up to pull from a list of computers.

2. I'm first running "Test-MyConnection" (if) the computer is online, I'm then calling a executable.exe.  This is the part I'm having issues with - I don't necessarily want to run a .exe here, but call an SCCM advert (pasted below from client center), or, I also have a vbscript that runs the advert I could call out to.  This advert would exist locally on every computer.  The part I'm unsure about, or how to code is having this advert run on each computer in the list of variables


SCCM Advert Code:
 get-wmiobject -query "SELECT * FROM CCM_Scheduler_ScheduledMessage WHERE ScheduledMessageID='SCCM00001-SCCM00002-5D2960FE'" -namespace "ROOT\ccm\policy\machine\actualconfig"
 

Open in new window

0
Powershell Enter-PSSession no longer working. Recently I started using the PowerShell command Enter-PSSession to run several commands on some remote PCs.

My workstation runs Windows 10 Pro, and the target computers all run windows 7 Pro this is in a domain environment and I'm doing this with admin credentials. It worked at first, but recently I've started getting an error whenever I try to run the Enter-PSSession command as shown in the attached screenshot.
screenshot of errorother users with the same permissions as myself do not get this message and are able to use Enter-PSSession without trouble.

Is it possible to somehow reset my PowerShell preferences/settings back to default and remove any extra modules I may have installed that could have caused this?
0
I need to search 2 email mailboxes for search terms and specific dates how can i do this in power shell on the server
1
This is using a Solaris 11.  We have a monitoring server that shows that this Solaris server is have a few spikes on the memory performance for 4 consecutive weeks. This may not seems to be a big problem, however, my management need to have a clearer picture on this.

In view of this, my senior wants to implement a process monitoring to see differences in processes (daytime,user,pid,ppid,vsz,rss,pcpu,command) in /var/adm/perf which is running every 5 Minutes. The main objective is so as we can see which process causing the memory spikes at any time. I am not a shell script expert. Please suggest how to write a script that can accomplish the above task.

Thanks in advance.
0
Have a Ruby script the ssh into multiple servers. I am trying to modify it so that it would first attempt  to use password and then 2nd attempt use a key.
Have script do each by there self however I need to have one script that will try to use password first then key.

Below is my script:
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'

USER = 'USER'
PASS = 'password'
KEY = "~/.ssh/id_rsa"
hosts = ['host1',  'host2',] 

hosts.each do |host|
  Net::SSH.start(host, USER, :password => PASS, :keys => KEY,
                   :auth_methods => ["password", "keys"], :port => 22,
                   :timeout => 5,
                   :non_interactive => true ) do |ssh|
     result = ssh.exec!('hostname')
     puts result
     result = ssh.exec!('hostname -i')
     puts result
     result = ssh.exec!("echo \'*** ****\'")
     puts result
     puts result
   end
end

Open in new window

0
have a rename oneliner, but I cant seem to get it to work

my contents look like this:, but mass quantity

100.10.in-addr.arpa
11.5.10.in-addr.arpa

I need them all to have a .db at the end so

11.5.10.in-addr.arpa.db
100.10.in-addr.arpa.db

I have this string that I use to echo the change to screen to make sure I like it, but it does not work right, I cant seem to get it to add the.db


for i in `ls`; do newname=`echo $i | sed 's/.arpa//'`; echo mv $i $newname; done

Open in new window


Then i used this one to change it

for i in `ls`; do newname=`echo $i | sed 's/.arpa//'`; mv $i $newname; done

Open in new window


can someone please help me mod this please.
0
Need to change a value in a Package.json file that looks like this
package.json  
{
  "name": "Test",
  "version": "0.1.0",
  "repository": {
    "type": "git",
    "url": "git@github.com/test.git
  },
  "license": "UNLICENSED",
  "private": true,
  "devDependencies": {
    "chromedriver: "75"
}


Below code gives me chrome driver version 75
CHROME_VERSION=$(cat package.json \
  | grep chromedriver \
  | head -1 \
  | awk -F: '{ print $2 }' \
  | sed 's/[",]//g')

echo $CHROME_VERSION


Using a bash script - can anyone help me with how to update the value from 75 to 76?

I need to update the chrome driver version from 75 to 76. (Update the chrome driver version from 75 to 76)
0
Team,

I have the below script which will provide the Top 10 Recievers in Exchange 2016.

The issue is that, its taking very long time to provide the output. I did tried using the Invoke-Command , but no luck.

$msgs1 = Get-TransportServer | Get-MessageTrackingLog -resultsize unlimited -EventId "Receive" -Start(Get-Date).AddDays(-30)

$msgs1| Group-Object -Property Recipients | Select-Object name,count | sort count -desc | select -first 10 | ft -auto

Open in new window





Thanks
Krish
0
Hello Experts,

I have the below scripts which will provide the Top 10 senders information for last one month.

$msgs = Get-TransportServer | Get-MessageTrackingLog -resultsize unlimited -EventId "Send" -Start(Get-Date).AddDays(-30)
$msgs | Group-Object -Property Sender | Select-Object name,count | sort count -desc | select -first 10 | ft –auto

I would like to see if it possible to export the result as Bar chart in Excel. Below is the sample output and i have attached the screenshot of
output in Bar chart format.

Output :

Name      Count
xyz.com      3531
llccc.net      2206
abcc.co      1497
Kcic.com      1458
Llcnet.com      935




Thanks in Advance.

Krish
output-chart.JPG
0
Become a CompTIA Certified Healthcare IT Tech
LVL 13
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

i am trying to  using  if condition in while loop .but  loop is coming out after one iteration .
In file_names.txt contain text file names.after getting the names i am using ssh to connect another server and get the count of that file which is present that server.
this if condition is working fine when tried individually by hard coding the name.  

cat /usr/local/apps/jethro/devl/bin/file_names.txt|while read -r line;
do
	echo $line
	
	if [[ ${line} == DSI_BC_DIM* ]]; 
		then
			echo ${line}
			echo "DIM"
			b=`ssh  amzphxjethro05 'zcat /md1/dev-scripts/PTD-Jethro-Stage/DSI_BC/'"${line}"' | wc -l'`
			echo ${b}
			echo `expr "${b}" - 1`
	else 
			echo "working"
			echo ${line}
			b=`ssh  amzphxjethro05 'zcat /md1/dev-scripts/PTD-Jethro-Stage/DSI_BC/'"${line}"' | wc -l'`
			echo $b
	fi 
done

Open in new window

0
Hello Team,

Is it possible to create our own web page using PSWA(powershell web access)?

I am trying to create a powershell based web page which will be accessed by Managers for approval of Mailbox storage.

Thanks
Krish
0
Hi, Shell experts,

could you help please

When I execute below aws cli, I get below output, but not in a single space separated and not sure it will be consistent as well.


$ policies=$(aws iam list-attached-role-policies --role-name TESTRole --region ap-southeast-2 --query 'AttachedPolicies[].PolicyArn' --output text)

arn:aws:iam::33333333333:policy/Policy1  arn:aws:iam::33333333333:policy/Policy2        arn:aws:iam::33333333333:policy/Policy3

Open in new window


my request, how to remove all the spaces and place single comma. tried below but not working as expected.
echo ${policies// /,}

Basically we need output like this.
arn:aws:iam::33333333333:policy/Policy1,arn:aws:iam::33333333333:policy/Policy2,arn:aws:iam::33333333333:policy/Policy3

Open in new window

0
Hi Bash, Shell Script experts,

kindly please help.

On a linux server, I need to update two property values. can we use two sed?

Before
cat /etc/config.conf | grep stunnel_check_cert
stunnel_check_cert_hostname = true
stunnel_check_cert_validity = true

Open in new window


After
stunnel_check_cert_hostname = false
stunnel_check_cert_validity = false

Open in new window

1
On Windows 10 images I created using sysprep audit mode-->Acronis Bootable True Image,  LAPS (local administrator password solution) we implemented doesn't work.  


The Local Administrator password string generated every day in the AD attribute editor doesn't work only for workstations I created using sysprep audit mode.  For workstations I created using sysprep OOBE it works fine.  

 Also, there are 2 corresponding ps scripts setup to work with LAPS:  1 that initially adds a domain-local administrator group to the workstation.  The second ps script adds domain user accounts into the local administrator group ,  then at the end of day removes the users from the group.  PS script part 1 fails only on workstations that were imaged using sysprep audit mode.  It doesn't fail on workstations imaged using OOBE.

The way I create the images is, 1)open sysprep 2) choose audit mode generalize/shutdown 3) shutdown PC 4) boot to Acronis True Image to create TIB file 5) restore TIB file to new workstation
0
I have bunch of IPs (like 5000) and I would like to find a reverse lookup.  I have a excel file where i have all the IPs. i want the script to read a file and do a reverse lookup and write the results in to a file.

what is the best way to put in a shell script .

please advise
0
I have about tons of servers, which includes different style of OS and version.

i have a landing server where i can ssh to all these servers with keys.

i need a script to run it remotely to all these servers and get the the following details. need space or tab in between so i can put it in excel

what is the best way to do using shell script with for loop to ssh to these machine. i can ssh to all servers using for loop and reading a tons of server name from a file.

hostname       OS      release       kernel version

i.e  
myhostname    Redhat  6.10   2.6.32-xxxx
0
i have a windows cmd script which has calls to other scripts
it runs tasks in consecutive order and is called from several config scripts
echo.starting upgrade on %oracle_sid% at %dt% >%mlog%

echo  hit a key to start 
pause

rem step 1
call:eecho "preparing source"
call %sdir%\prepare_source_12102.cmd 

rem step 2
call:eecho "creating standby 12102"
call %sdir%\create_standby.cmd

rem step 3
call:eecho "rollforward standby"
set activate=NO
call %sdir%\activate_standby.cmd

echo hit a key to ACTIVATE STANDBY 
pause 

rem step 4
call:eecho "activate standby"
set activate=YES
call %sdir%\activate_standby.cmd

echo hit a key to start upgrade to 12.1
pause 

rem step 5
call:eecho "upgrade to 12.1.0.2"
call %sdir%\upgrade_db_12102.cmd

rem step 6
call:eecho "post upgrade on 12.1.0.2"
call %sdir%\post_upgrade_db_12102.cmd
call:eecho "end of post upgrade on 12.1.0.2"

echo hit a key to upgrade to 12.2
pause

rem  step 7
call:eecho "preparing source for 12.2.0.1"
call %sdir%\prepare_source_12201.cmd 

rem step 8
call:eecho "upgrade database to 12.2.0.1"
call %sdir%\upgrade_db_12201.cmd 

rem step 9
call:eecho "post upgrade database to 12.2.0.1"
call %sdir%\post_upgrade_db_12201.cmd 
call:eecho "end of post upgrade database to 12.2.0.1"

echo hit a key to switch sids
pause

rem step 10
call:eecho "rename sids %oracle_sid% to %dest_sid%"
call %sdir%\switch_sid.cmd %dest_home_2% %oracle_sid% %dest_sid%
call:eecho "end of switch sids to "%dest_sid%"

goto exit

:eecho
title 

Open in new window

0
Hi All,

Really stuck in one place. I am new to plsql and shell scripting.

I have a shell script which is taking $1 parameter as JOB_ID while executing. means i am passing JOB_ID as $1 while running the script
like
sh test.ksh SW -- where SW is my JOB_ID

Now i need to create a new function inside an already existing package in oracle. This function should be called from script.
It should take $1 as input parameter and then i have a query which should go in function like-

select count(*) from job_tables where job_id=$1

Now the result can be either 0 or 1.

if result is 0 then i need to set a variable
JOB_NO in shell script as /home/users/abc

if result is 1 then i need to set
JOB_NO in shell script as /home/users/def

Please help me in solving this. How should i write and approach
0
Learn SQL Server Core 2016
LVL 13
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

CentOS 7 booting yad script on startup, tried making service script but when starting the service the status give me the following:

[patrol@ppt_ae33sf etc]$ systemctl status rc-local
  rc-local.service - /etc/rc.d/rc.local Compatibility
    Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
    Active: active (exited) since Thu 2019-05-30 12:21:27 EDT; 2h 19min ago
      Tasks: 0

May 30 12:21:26 ppt_ae33sf systemd[1]: Starting /etc/rc.d/rc.local Comaptibility...
May 30 12:21:27 ppt_ae33sf yad[5506]: cannot open display:
May 30 12:21:27 ppt_ae33sf sudo[5789]:                root : TTY=unknown ; PWD=/ ; USER=root ; COMMAND=/bin/nmtui
May 30 12:21:27 ppt_ae33sf sudo[5789]: pam_limits(sudo:session): invalid line '* -nofile 2048' - skipped
May 30 12:21:27 ppt_ae33sf sudo[5789]: pam_limits(sudo:session): invalid line '* -nofile 2048' - skipped
May 30 12:21:26 ppt_ae33sf rc.local[5494]: Your terminal lacks the ability to clear the screen or position the cursor.
May 30 12:21:27 ppt_ae33sf yad[5506]: cannot open display:
May 30 12:21:26 ppt_ae33sf systemd[1]: Started /etc/rc.d/rc.local Comaptibility.


It looks like Yad is trying to access a open display. is their a way to prevent this or a way to bypass the message and make this script start on startup? any help is greatly appreciated.
0
I have few OS commands which I need to run only through ADMINISTRATOR's CMD console
please advice how to call such batch script

example :TEST.BAT
how to make sure below  script called from admin cmd console
==

echo " Hello"

==
0
Hi Expert

good day

I trying to automate the process of manual generating of the patching report on the Redhat Linux distribution 7.3.

Need help, how to generate a python script or shell script to capture the following output to a csv files.

Errata ID,  Severity, Package Name Packages, before patching and after patching.

Many thanks
0
machineinfo.txtHi Experts,

In Bash unix shell I would like to search text in a file named “machineinfo.txt” (contains information about software installed on a computer) and search/filter on an install date = “” line between a specific date range from 20190401 to 20190513 and output the following lines in date order (most recent date at top of list) from the results of the search based on the date range (below is example output)

DisplayName = "Symantec Endpoint Protection
InstallLocation = "C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\14.2.1031.0100.105\"
DisplayVersion = "14.2.1031.0100"
InstallDate = "2019022

I’m not sure what command needs to be used, any help appreciated please? Attached is an example of the machineinfo.txt file. I’ve kept the file small with just a few software entries.

Thanksmachineinfo.txtmachineinfo.txt
0
Hello Team,

I am trying to setup a automatic Lync creation script. The script should check if the mailbox is created or not and then enable lync account.

Please let me know if there is any possiblities.

Thanks
Krish
0
Hello Team,

I would like to setup a alert system in Exchange 2010 environment, where once the mailbox is created, it should trigger the email to the specific DL in HTML Format.

Below is the example of the email.

Subject : New Mailbox Created for "User Name"
Body : (This should contain a Tabular column in HTML Format which contains the objects Name, Email Address)

I appreciate any help in this regard.

Thanks
Krish
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.