Go Premium for a chance to win a PS4. Enter to Win

x

Shell Scripting

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 trying to come up with a Powershell script that will search multiple computers and list the name of the computer with what services has a specific account running that service and export to a CSV file.

Ex. ComputerName, Displayname, StartName, State
      ComputerA, BITS, UserA, running
0
Keep up with what's happening at Experts Exchange!
LVL 11
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Hello Experts,
how does make a bat file for continuous Ping multipal IP with background Colour changes ?
for example:-
start ping -t 192.168.207.11 -l 0
start ping -t 192.168.207.12 -l 0
start ping -t 192.168.207.13 -l 0
start ping -t 192.168.207.14 -l 0
start ping -t 192.168.207.15 -l 0
0
Hello all,  
Running a vbs script with FTP commands and this error popped up. -2147023741

Just did a rerun and all went fine,   scanned the web for the error and nothing showed up.  
Any ideas on what it could of been?  
Thanks
0
What set -e dose in this shell script.

set -e



#!/usr/bin/env sh

ANSIBLE_ROOT=${ANSIBLE_ROOT:-~/ansible}
scl enable python27 bash <<!
set -e
export https_proxy=https://10.198.140.122:8080
if [ ! -d "$ANSIBLE_ROOT/bin" ]
then
    virtualenv "$ANSIBLE_ROOT"
    . "$ANSIBLE_ROOT/bin/activate"
    echo "Installing latest version of ansible"
    pip install ansible -i https://artifactory.global.raju.com/artif4actory/api/pypi/pypi-release/simple
    pip install docker-py -i https://artifactory.global.raju.com/artifactory/api/pypi/pypi-release/simple
    pip install docker-compose==1.15.0 -i https://artifactory.global.raju.com/artifactory/api/pypi/pypi-release/simple
    deactivate
fi
!

Open in new window

0
help me to understand the below lines in below shell script..

Why we need to use virtualenv "$ANSIBLE_ROOT" .... and what is the use of virtualenv here ....

and how activate and deactivate worked ...i am bit confused how activate and deactivate keywords worked here..
. "$ANSIBLE_ROOT/bin/activate"
deactivate


and also how pip works with -i option...i.e. below

pip install docker-compose==1.15.0 -i https://artifactory.global.raju.com/artifactory/api/pypi/pypi-release/simple


#!/usr/bin/env sh

ANSIBLE_ROOT=${ANSIBLE_ROOT:-~/ansible}
scl enable python27 bash <<!
set -e
export https_proxy=https://10.198.140.122:8080
if [ ! -d "$ANSIBLE_ROOT/bin" ]
then
    virtualenv "$ANSIBLE_ROOT"
    . "$ANSIBLE_ROOT/bin/activate"
    echo "Installing latest version of ansible"
    pip install ansible -i https://artifactory.global.raju.com/artif4actory/api/pypi/pypi-release/simple
    pip install docker-py -i https://artifactory.global.raju.com/artifactory/api/pypi/pypi-release/simple
    pip install docker-compose==1.15.0 -i https://artifactory.global.raju.com/artifactory/api/pypi/pypi-release/simple
    deactivate
fi
!

Open in new window

0
I have a command like this ...could you explain what each term doing in below command.

scl enable python27 bash <<!
0
i am  quite confused about this below shell variable declaration. and what us the benifit out of this?

devops@[~] $ ANSIBLE_ROOT=${ANSIBLE_ROOT:-~/ansible}
devops@[~] $ echo $ANSIBLE_ROOT
/home/devops/ansible
devops@[~] $

=========================================================================>

root@[devops] # ANSIBLE_ROOT=${ANSIBLE_ROOT:-~/ansible}
root@[devops] # echo $ANSIBLE_ROOT
/root/ansible
root@[devops] #
0
I'm not even sure I can do this, but I want to have a script that ssh's to another server and creates a tar file on the remote server.  Is that even possible?  Here's what I have been working with, which isn't very much because I can't figure out how to make it work.

Thanks in advance for any help!
David

#!/usr/bin/ksh

server=$1

ssh $server 'tar cvf $server.logs.tar.gz /opt/bmc/Patrol3/log/Patrol*'
0
Hi Experts,

if [[ "$DBS" -eq 1 && "$DBS" -ne VFEEDBACK* ]]
 then
        DS=`echo "$i"`

How do I write the if statement in the correct way
0
Folks,

I'm using alacarte to edit the menus for a centos box... however the changes only work within my user's account, is there anyway to set the settings system wide (for all users?)

thanks for looking
0
Ask an Anonymous Question!
LVL 11
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Hello,

I need a way to look at one csv file (DNS-record.csv that looks like this. But it has a few thousand lines

DNS Name,IP Address,Text Record
dcdiag-test-record.corp.sark.com,1.1.1.1,
omniview.corp.sark.com,10.0.0.12,
omniviewwebprd.corp.sark.com,10.0.0.12,
ocrntovftp.corp.sark.com,10.0.0.14,
omniviewftpprd.corp.sark.com,10.0.0.14,

Open in new window


File 2 named: Global-text.csv looks like this, and it has thousands of lines

header-txtrecord,fqdn*,_new_fqdn,text*,_new_text,comment,disabled,ttl,view,EA-Site
txtrecord,dcdiag-test-record.corp.sark.com,,31f8d425a979fff1cbc064fedc6af8cd7f,,,FALSE,3600,Internal-RPZ,
txtrecord,omniviewwebprd.corp.sark.com,,00a151deec7b2c49fcb106daab945e376f,,,FALSE,3600,Internal-RPZ,
txtrecord,zbr4185224.ocr,,00444e8f6a21e53453f0e11a6d6f1e9f67,,,FALSE,3600,Internal-RPZ,

Open in new window


What I wish it can do is look in file 1 and search in file 2 named Global-text.csv for a matching DNS name (column 1) to a matching  txt record on the 4th row ( text*)  

The Global-text.csv has every single txt to hostname in it. But Im only interested in what it finds from file 1"DNS-record.csv"
If found, then output the results named output.csv with the above format from ( file 2 Global-text.csv )

Is t here a way to shell script, perl maybe or even grep/awk? I am using a mac as well

I would appreciate any help
0
Dear Experts, I got this error when connecting remotely to Exchange Management Shell  from a domain-joined PC. Could you please revise and help? Many thanks in advance.

(The credential is admin account and correct)
error.PNG
0
Hello Folks,
I'm trying to create a bash script and I need to translate this to .SH format

pwd #example command
if [ $? -ne 0 ] 
then echo "bad input of the command try again"  #the command should re-do*
else  fi
echo "next command" #more commands continue with the rest of the bash

Open in new window


*I just don't know how to loop it, i know if I was  in batch then i can set up routines but i'm not sure if those are possible to apply here
0
I'm having an issue with trying to get a heredoc in a ksh script to write to a file.  I have used the following code.  It creates the file, but doesn't write anything in it.

Thanks!
David

CFGFILE=/home/share/daldrid/work/tasks/bmc/configfile/agenthwdebug.txt

echo <<EOF > $CFGFILE
PATROL_CONFIG

  "/SENTRY/HARDWARE/debugEndTime" = { REPLACE = "$DATE $TIME" },

  "/SENTRY/HARDWARE/debugMode" = { REPLACE = "1" },

  "/SENTRY/HARDWARE/automaticReinitialization" = { REPLACE =  "1" }
EOF
0
I have an Access DB, in it I have an authentication form for users, I want to import data using a powershell script, but when the script opens the DB fails to import because the form does not enter the access data. My code is this and I could not make it work

$database = 'D:\db.accdb'
$Acc = New-Object –comObject Access.Application
$Acc.Visible = $false
$Acc.OpenCurrentDataBase($database)
$Acc.DoCmd.OpenForm('Form_Login_bd')
$AccForm = $Acc.Forms.item('Form_Login_bd')
$AccForm.Controls.Item("txt_login").value = "Test_Admin"
$AccForm.Controls.Item("txt_contrasena").value = "Test_Admin123"
.
.
.
script to import data
.
.
.

Any idea how to solve it
0
I have accidentally Rename more than 100 files in one Folder in Unix  like

File_Namee to   July_2016_FIle_name  Like all the file prefixed to same String "july_2016_"   How can I Reverse this action through Script?

Thank you Very Much.
0
Hi,
I have a requirement to fetch data in xls file using shell script, the requirement is simple whatever the table data that has to shown in xls file,

REGION_ID      REGION_NAME
1                      hello, you will be covering these many locations in this week
                        1.Perth
                        2.Sydney
                        3.Melbourne

I want to to show the same data in xls file but when I am generating it is not showing new line in xls cell instead the value is continued with the spaces which is incorrect.

wrong output - "hello, you will be covering these many locations in this week 1.Perth 2.Sydney 3.Melbourne"

for more please see the attached screenshot.

CREATE TABLE REGIONS
  ( REGION_ID NUMBER, REGION_NAME VARCHAR2(500)
  );
  
SET DEFINE OFF;
INSERT
INTO REGIONS
  (
    REGION_ID,
    REGION_NAME
  )
  VALUES
  (
    1,
    'hello, you will be covering these many locations in this week 
1.Perth 
2.Sydney 
3.Melbourne'
  );
INSERT
INTO REGIONS
  (
    REGION_ID,
    REGION_NAME
  )
  VALUES
  (
    2,
    'hello, you will be covering these many locations in this week 
1.NZ 
2.Tasmania 
3.NSW'
  );
INSERT
INTO REGIONS
  (
    REGION_ID,
    REGION_NAME
  )
  VALUES
  (
    3,
    'hello, you will be covering these many locations in this week 
1.Albany 
2.Busselton 
3.XYZloc'
  );
INSERT
INTO REGIONS
  (
    REGION_ID,
    REGION_NAME
  )
  VALUES
  (
    4,
    'hello, you will be covering these many locations in this 

Open in new window

0
I can run the following command and get a successful return code:

+ ssh ovmmgr01 '/opt/bmc/Patrol3/Linux-2-6-x86-64-nptl/bin/pconfig -version'
pconfig V10.7.00i Linux 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:14 EST 2007 x86_64 Build_20170217080901 Feb 17 2017
+ echo 0
0

If I try to add a grep, it fails.

+ ssh server1 '/opt/bmc/Patrol3/Linux-2-6-x86-64-nptl/bin/pconfig -version | grep V10'
pconfig V10.7.00i Linux 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:14 EST 2007 x86_64 Build_20170217080901 Feb 17 2017
+ echo 1
1

Any help would be greatly appreciated!

Thanks,
David
0
I need some fancy way to look in my file named "ocr-delete-records-pass-3.csv" in  that file there is a column B I need to match on my other file  "global-TXT-Records-ALL.csv" and spit out a new file called "text-remove.csv" I also need to preserve the format in the first file "ocr-delete-records-pass-3.csv" when the new output is produced.

In short I have a list of names in ocr-delete-records-pass-3.csv which I need it to look in  the master "global-TXT-Records-ALL.csv"  file for a match on the TXT record in column D from the "global-TXT-Records-ALL.csv" file.

If this can be done please advice

Thank you !
ocr-delete-records-pass-3.csv
global-TXT-Records-ALL.csv
0
[Webinar] Cloud Security
LVL 11
[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

I winder if anyone could help. Does anyone has any information on this?

A batch file required to run on a folder that will move into other folders based on file name and type.

What we have are scans coming off a locally attached scanner into one folder, need to sort from there where they will be moved to with the click of a cmd file

Example

Scans go to c:\scans

Format PDF

Sort will be filename, example car, truck, bike etc

Pre-existing folders in c:\Scans\Car, c:\Scans\truck, c:\Scans\bike

Any help would be appreciated

Thanks

John
0
Greeting Experts,

 I need help creating a script I can use to scan a list of websites and get the status code of each one ( i.e., 301, 302, etc.) and then put the output into a .csv file. Can somebody help me with this request
1
There are two input files: input1.txt is the actual file, input2.txt contains count of value in column 1 as per coulmn 2 from input1.txt.
need output which remove lines from input1.txt  (output.txt for reference)


input1.txt>>
abc[1.0],partition=xyz,deployedTime=20170302T2316388270600
abc[2.5],partition=xyz,deployedTime=20160713T2040505210500
bca[2.3],partition=yxz,deployedTime=20160713T2040505210500
bca[2.4],partition=yxz,deployedTime=20160813T2040505210500
bca[1.2],partition=yxz,deployedTime=20170302T2316388270600
bca[2.4],partition=xyz,deployedTime=20160813T2040505210500
bca[2.3],partition=xyz,deployedTime=20170713T2040505210500

input2.txt>>
2 abc xyz
3 bca yxz
2 bca xyz

output.txt>> should be in below format(have to remove latest version of column 1 as per coulmn 2 from input1.txt based on deployedTime)

abc[2.5],partition=xyz,deployedTime=20160713T2040505210500
bca[2.3],partition=yxz,deployedTime=20160713T2040505210500
bca[2.4],partition=yxz,deployedTime=20160813T2040505210500
bca[2.4],partition=xyz,deployedTime=20160813T2040505210500


Need help for generic command, that will work if input file contains n number of line.
0
can i get any freelancers do powershell scripting
0
I'm migrating to Office 365 from Exchange 2013 and I need a PS script to output either to csv or html that gives me shared mailboxes, calendars, or other users mailboxes  that all mailbox users in a specific OU in AD has access to.

I do not need the permissions or any other information other than the users in the specified OU and what they have access to.   Making it readable, for example instead of listing the user each time and the shared access, just list the user once and the shared objects; if not no big deal.

I've tried multiple scripts and variation and they have not given me the results I'm looking for. I'm hoping that an awesome scripting guru can make it happen.

Thank you in advance
0
Trying to create a quick script for the helpdesk to change calendar permissions on PowerShell through the O365 connector and i was wondering what do i need so that the console doesn't close after the below is run and they can continue with running some commands.

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Open in new window


I've seen that running it with the -NoExit switch could work but it's a little cumbersome, is there a better way from within the script?

Help as always is appreciated!
0

Shell Scripting

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.