Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x

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

Hi experts.
Would like to save the content to a file rather than displaying it from python script. Since I'm new to python pls help me
Have attached a python script. right now it prints the content to stdout.

# I think, this line
self._display.display(json.dumps(output, indent=4, sort_keys=True))

Open in new window


Is it possible to have a variable declared for directory for json file location and write the file there?

Source File location:
https://codeclimate.com/github/ansible/ansible/lib/ansible/plugins/callback/json.py

thanks in advance.
json.py
0
Get your problem seen by more experts
LVL 11
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Hi,

I would like to use grep and and sed to replace string to something else .

Eg :

When i use grep, there are 97 result :

root@svr51 [/home/xxx/public_html/akaunting]# grep -lir "ini_set" ./* | wc -l
97

I would like to replace "ini_set" found in those file to "//ini_set" , to comment/disabled that line.

Anybody can help to construct full grep and sed command ?

Please let me know also the location where i should run that command to avoid it to replace file in wrong location.

Thank you.
0
Good day,

I have this bash script where i can generate a from-to ip range.  

However I need something similar in kornshell and need it to generate it's own /24 network with random hostnames from any single ipadress input
 
So like 192.168.1.5 will generate the full 192.168.1.1/24 with hostnames.



#!/bin/bash
#
# Convention for octets:  A.B.C.D

# Variable setup section...
#
# Split up IP addresses into seperate variables for each octet
IPLO=(`echo "$1" | awk '{split($1,a,"."); print a[1]" "a[2]" "a[3]" "a[4]}'`)
IPHI=(`echo "$2" | awk '{split($1,a,"."); print a[1]" "a[2]" "a[3]" "a[4]}'`)
#
# Put array contents into nicely named vars for less confusion
#
OCTA=${IPLO[0]}
OCTB=${IPLO[1]}
OCTC=${IPLO[2]}
OCTD=${IPLO[3]}
OCTAHI=${IPHI[0]}
OCTBHI=${IPHI[1]}
OCTCHI=${IPHI[2]}
OCTDHI=${IPHI[3]}
OCTDMAX=255             # Max default value for D Octet to loop to
FINISHED=0              # Variable used for loop state checking

# Syntax sanity check; check all vars are populated etc
for i in 0 1 2 3
do
        if [ -z "${IPLO[$i]}" ] || [ -z "${IPHI[$i]}" ]; then
                echo "Usage: $0 [from ip] [to ip]"
                exit 1
        elif [ "${IPLO[$i]}" -gt "255" ] || [ "${IPHI[$i]}" -gt "255" ];then
                echo "One of your values is broken (greater than 255)."
                exit 1
        fi

done

# Until FINISHED variable is set to 1, loop the loop.
# FINISHED var is used to determine when done as the …
0
I want to log into a website using a username and password, so I copied the following code and executed. In result the webpage is opening but its not logging into the webpage and getting the following error.

Any suggestions?

$ie = New-Object -com InternetExplorer.Application 
$ie.visible=$true
$ie.navigate("url") 
while($ie.ReadyState -ne 4) {start-sleep -m 500} 
$ie.Document.getElementById("ctl00_username").value = "abcdef" 
$ie.Document.getElementById("ctl00_password").value = "123456" 
$ie.Document.getElementById("ctl00_login").click()
start-sleep 20 
$ie.Document.body | Out-File -FilePath C:\Users\averm\Documents\adi\test\web123.txt 

Open in new window


Exception from HRESULT: 0x80020101
At line:7 char:1
+ $ie.Document.getElementById("ctl00_usernamerequiredvalidator").value  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
 
Exception from HRESULT: 0x80020101
At line:8 char:1
+ $ie.Document.getElementById("ctl00_passwordrequiredvalidator").value  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
 
Exception from HRESULT: 0x80020101
At line:9 char:1
+ $ie.Document.getElementById("ctl00_login").click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

Open in new window

0
I have roughly 1000 files from a website on my local hard disk.  I want to determine if any of these files have:
http://localhost

Open in new window

on any line, except skip the ones that have:
comment="http://localhost

Open in new window


Thus, if there are any "HREF="http://localhost" entries, it would show up, or any "SRC="http://localhost", it would show up in the results.

Any easy way to do this?
0
Hello,

what I would like is a batch file that will get the folder structure of the drive into a menu structure so that you can select the folder you want to go into, and once you select a folder from the menu, the subfolders of that folder would then be listed in a menu as well, and so on and so forth as deep into the folder structure as you want to drill down to. And in each menu would have a "backup current folder level" and a "list all contents of current folder" and if possible include a "go to previous folder" option.

 Basically I would like to run the batch file and be given a menu of the folders only of the c drive, then be given an option to either backup the current folder, list the files of the current folder in case I wanna to only backup one file from that folder, or select a subfolder and then be given the same options with the addition of the go to previous folder option for subfolders.

 I've tried and tried to write something like this but I'm not a strong batch script writer and just can't get anywhere with it.

 Thank you very much in advance for your help,
Ryan
0
Hi there,

I'm trying to dynamically create this string in a variable so that I can then run "eval" on it and run the command remotely on another Linux VM.

ssh oracle@10.41.22.69 "md5sum /data/oracle/dpdump/onegeo/ONEGEO20171214.DMP | awk '{ print \$1 }'"

I can get the string working until the "awk" part and then no matter what I try, I keep getting errors when trying to properly create the rest of the string with single quotes.  The double and single quotes in the string are all required.  

I tried this but it didn't work, what am I missing?
md5command='ssh oracle@10.41.22.69 "md5sum /data/oracle/dpdump/onegeo/'$DMPfilename' | awk '\'{ print \$1 }\''

Any help would be appreciated!!

Thanks,
- Christian
0
hello sorry for my english

is a script to upload files juste me i would like detect the new files in forlder and upload files or folder in my ftp in cron job im a noob in script shell and i need help ty :)
#!/bin/sh
HOST='ftp.example.com'
USER='yourid'
PASSWD='yourpw'
FILE='file.txt'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
binary
put $FILE
quit
END_SCRIPT
exit 0

Open in new window

0
I am new to the Perl syntax but have used OOP from Pascal, to C++ to C#.

Can you give me an example of the syntax for using OOP in Perl?

Thanks.
0
I understand Perl is part of my Mac OS, but I hear I would be best served to ensure any programming (learning) in Perl should be isolated so as not to upset the functioning of my El Capitan system.

What kind of installation shall I make to ensure the Perl I access from Mac Terminal does not touch any system files?

Thanks.
0
Hire Technology Freelancers with Gigs
LVL 11
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Hi
I like to parse my command line arguments in a function.
The following script does not work
var1=$1
var2=$2
DB_UserName=
DB_Password=

usage(){
    echo "usage: sqlexed [-u username ] [-p password]" 1>&2; exit 1;
}

processparameters(){
while getopts ":s:p:" o; do
    case "${o}" in
        s)
            DB_UserName=${OPTARG}
            ;;
        p)
            DB_Password=${OPTARG}
            ;;
        *)
            usage
            ;;
    esac
done
shift $((OPTIND-1))

if [ -z "${DB_UserName}" ] || [ -z "${DB_Password}" ]; then
    usage
fi
}

Main() {
processparameters $var1 $var2
}
Main | tee autosql.log


Not able to process the command line arguments. What do I have to change to be able to parse them in a function_
thx
0
Hi
with a unix command I want to replace all occurrences in a text file
1. LF by CRLF
2. LF by NL
3. CRLF by NL
5. NL by LF

Where
Abbreviation      hexvalue      decvalue      Escape sequence
LF                      0A                10               \n
CR LF                0D 0A      13 10      \r\n
CR                        0D              13              \r
RS                       1E                30      
LF+CR                 0A 0D      10 13      \n\r
NL                        15                  21      \025


Many thanks
0
I need my website to extract the data from a PDF and generate a CSV file. And I hope to do this on the front end, inside the client browser. But, if required, I could to this extraction on the back-end.

The PDF would be a month merchant credit card statement. The data I would extract to a CSV would be the numerous transactions.

What web technology can do this? And without human intervention.

Thanks.
0
My database team supports approximately 70 software developers.  We have inherited many database maintenance utility scripts, that automate several routine database activities.  In our dynamic software development environment we all developers to choose the version of the database schema to run their code against.  

Our development environment is a unix variant, i.e. Oracle Solaris.  When developers install new versions of the application they must associate the correct version of the database schema.  So our team has devised a script to handle this chore for each developer.  The problem is this script generates a log file and the naming of this log files sometimes gets missed name with a previous version.  

Log file mechanics:

•      Log file is named same as script being run
o      Log file name is identical to script with a “g” plus number extension
o      Example:  script=DumpRecord logfile=DumpRecord.g1
•      Print all current active variables
•      Print all echo statements in script


This database utility script is run at a high rate of frequency almost concurrently by some users.  The script allows J2EE software developers to update their individual schemas to run against their application in their isolated environment.  Developers are separated by Oracle Solaris Zones, however supported by a single database.  

Any ideas to avoid naming conflicts?
0
Greeting Experts,

I need help creating PowerShell script to read the name multiple files (over 2,000 files names) in a file directory and then import that information into a ".csv" document. Can somebody help me with this task...
0
I am writing shell script to create PV,VG,LVM and mountpoint and FS.

1. I am getting not-root disks using below command

PDEVICE=`lsscsi --device | grep -v "\:0\]$" | awk '/dev/{for(i=1;i<=NF;i++)if($i~/dev/)print $i}'`

Open in new window


2. Getting the PV's and checking whether the specific PV has attached to any VG or not as below.

VDEVICE=`/sbin/pvs | egrep -iv "(rootvg|PV)"  | awk '{print $1}'`

Open in new window


3. After that comaring these two arrays which PV's are not added to VG so that i am trying to add the missed devices to VG but some logic i am missing here ... can any one help in this ASAP please.

#! /bin/bash



PDEVICE=`lsscsi --device | grep -v "\:0\]$" | awk '/dev/{for(i=1;i<=NF;i++)if($i~/dev/)print $i}'`

echo ${PDEVICE[@]}


VDEVICE=`/sbin/pvs | egrep -iv "(rootvg|PV)"  | awk '{print $1}'`


echo ${VDEVICE[@]}

echo "Comparing the both the PV values"

for i in "${PDEVICE[@]}"
 do
    for j in "${VDEVICE[@]}"
 do
     if [ "${i[@]}" != "${j[@]}" ]
     then
      echo "${i[@]}"
     else
       echo "${j[@]}"
fi

done
done

Open in new window

0
Hello Experts,
I am getting error while execute script from Linux system...

[root@119 bin]# ./BOD.sh
./BOD: -c: line 7: syntax error: unexpected end of file

Script:-
[root@119 bin]# vim BOD.sh
   1 #!/bin/bash
  2 export DISPLAY=:1
  3 cat /root/version.txt |  while read output
  4 do
  5 gnome-terminal \
  6         --tab -t "SMM" -e " sh -c 'sleep 10s; ./startapp SMM' "\

[root@119 ~]# cat version.txt
cd /home/rajat/Desktop/Symbol_4.1.1.1_0812
0
hello experts
while i am trying to using get-telnet command via powershell, but looks like there is not such command by default, does it necessary to import some module like activedirectory or other steps to make it out?

thank you
0
Hi, i have a java program, it will fetch the data from oracle data base and it will be the output. so now what i need is ? using shell script i need to get the output from that java code will it pos/
0
Upgrade your Question Security!
LVL 11
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Hi,
I have a java program, it will fetch the data from oracle data base and it will be the output. so now what i need is ? using shell script i need to get the output from that java code will it pos? Need a shell script to do this activity..
0
How can we Transfer one folder to another folder on windows server of big size about 300 GB. I have to do automation via Jenkins.
0
I have 1000+ of these - and it appears the parent process for each I have checked is the same command... not sure what is going on... any ideas?


8012     32605  0.0  0.0 110016  1264 ?        S    01:21   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32610  0.0  0.0 110016  1268 ?        S    01:22   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32611  0.0  0.0 110016  1268 ?        S    01:21   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32617  0.0  0.0 110016  1272 ?        S    01:21   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32618  0.0  0.0 110016  1264 ?        S    01:22   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32623  0.0  0.0 110016  1268 ?        S    01:21   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32625  0.0  0.0 110016  1268 ?        S    01:22   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32629  0.0  0.0 110016  1268 ?        S    01:21   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32632  0.0  0.0 110016  1268 ?        S    01:22   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32635  0.0  0.0 110016  1268 ?        S    01:21   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32639  0.0  0.0 110016  1272 ?        S    01:22   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32641  0.0  0.0 110016  1268 ?        S    01:21   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32646  0.0  0.0 110016  1272 ?        S    01:22   0:00 /bin/csh test -d /usr/lib64/qt-3.3
8012     32647  0.0  0.0 110016  1268 ?     

Open in new window

0
Where can I obtain a good tutorial on power shell scripting. Also where can I obtain canned scripts
0
Eventhough there are no big files there still /opt/ is showing 100% full it very confusing to me. Can anyone help me on this please


root@[opt] # lsof | grep -i deleted
root@[opt] #

Open in new window


root@[opt] # lvs
  LV          VG                  Attr       LSize   Pool Origin  Data%  Meta%  Move Log Cpy%Sync Convert
  isvol1      HKLVAUEDM08_applvg1 -wi-ao----  10.00g
  isvol2      HKLVAUEDM08_applvg1 -wi-ao----  10.00g
  isvol3      HKLVAUEDM08_applvg1 -wi-ao----  10.00g
  tsavol      HKLVAUEDM08_applvg1 -wi-ao----  10.00g
  wmstorage   HKLVAUEDM08_applvg1 -wi-ao----  10.00g
  homevol     rootvg              -wi-ao----   3.91g
  oprvol      rootvg              -wi-ao---- 320.00m
  optvol      rootvg              owi-aos---   3.91g
  optvolsnap  rootvg              swi-a-s---   3.94g      optvol  95.39
  rootvol     rootvg              owi-aos---   5.88g
  rootvolsnap rootvg              swi-a-s---   2.91g      rootvol 69.49
  scbmonlv    rootvg              -wi-ao----   1.00g
  semavol     rootvg              -wi-ao----   1.00g
  swapvol     rootvg              -wi-ao----   5.88g
  tmpvol      rootvg              -wi-ao----   3.91g
  usrctmvol   rootvg              -wi-ao----   2.94g
  usrgemsvvol rootvg              -wi-ao----   1.00g
  usropenvvol rootvg              -wi-ao----   1.97g
  varvol      rootvg              owi-aos---   3.91g
  varvolsnap  rootvg              swi-a-s---   3.94g      varvol  88.16

root@[opt] # df -PH | grep -i "/opt" | grep -i root

Open in new window

0
Please see the attached XML, there are multiple resources,

I want to be able to find the resource whose name is "jdbc/PegaRULES" and create a new xml file which has only that resource.

For example: newfile.xml should be like:

<?xml version='1.0' encoding='utf-8'?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- The contents of this file will be loaded for each web application -->
<Context>

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
	
<Resource
			auth="Container"
			name="jdbc/PegaRULES"
			type="javax.sql.DataSource"
			maxActive="100"
			maxIdle="30"
			maxWait="10000"
			username="user1"
			password="password1!"
			

Open in new window

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.