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

Hello ,

I want to appy a system command with arguments from variables but i could not find an example any body has experience about this ?


This is what i want to do
system("/bin/bash  /etc/a.sh   %d %d",val1,val2);
0
Free Tool: Path Explorer
LVL 9
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Hi,

I am writing a script which connects via server remotely and run the sql script but the thing is i am passing process ids as paramerters  to kill the process of remote server here is the way i am sending

shell script :
echo "Pid :" ${pid[$i]}
      output=$(ssh -o StrictHostKeyChecking=no oracle@$HOSTNAME -p 9292  "bash -l -c sqlplus @"</home/oracle/process.sql ${pid[$i] )

Following is the sql script :

/as sysdba
            whenever sqlerror exit sql.sqlcode;
            SET HEADING OFF;
            SPOOL processOutput.txt
       
            select DISTINCT
            s.CLIENT_IDENTIFIER
            from v$session s, v$process p, v$sql q
            where s.paddr = p.addr      
            

and p.spid IN ($1,$2)

           and s.sql_id = q.sql_id(+);
            spool off;
            exit;

getting  ERROR at line 5:
ORA-00911: invalid character

line refering the error is hilighted.
0
Hello All,

Below script works fine and gets the output, I am planing to run this script against 50 Machines the output should have hostname/computername column. Thanks for help  

Import-module servermanager ; Get-WindowsFeature | where-object {$_.Installed -eq $True} | Select-Object name, d
isplayname, installstate

Open in new window

0
Hi Experts,
could you advise what is the best way to sort directories which has string with number prefix in bash please?

Scenario/Actual
DIR_NAME_Drop0
DIR_NAME_Drop1
DIR_NAME_Drop10
DIR_NAME_Drop2
DIR_NAME_Drop3
DIR_NAME_Drop4
DIR_NAME_Drop5
DIR_NAME_Drop6
DIR_NAME_Drop7
DIR_NAME_Drop8
DIR_NAME_Drop9


Expected
DIR_NAME_Drop0
DIR_NAME_Drop1
DIR_NAME_Drop2
DIR_NAME_Drop3
DIR_NAME_Drop4
DIR_NAME_Drop5
DIR_NAME_Drop6
DIR_NAME_Drop7
DIR_NAME_Drop8
DIR_NAME_Drop9
DIR_NAME_Drop10

Script for your reference
mkdir DIR_NAME_Drop2
mkdir DIR_NAME_Drop3
mkdir DIR_NAME_Drop10
mkdir DIR_NAME_Drop0
mkdir DIR_NAME_Drop1
mkdir DIR_NAME_Drop4
mkdir DIR_NAME_Drop5
mkdir DIR_NAME_Drop6
mkdir DIR_NAME_Drop7
mkdir DIR_NAME_Drop8
mkdir DIR_NAME_Drop9

Open in new window

0
I have been using this power shell command to create a text files that lists the currently installed programs on Windows 10 computers:

Get-WmiObject -Class Win32_Product | Select-Object -Property Name > C:\PCapps.txt

Open in new window


The problem is that this command lists only the names of the installed programs.

I would like to run a command that will display the complete list of everything that is displayed within the Programs and Features applet: Software name, publisher, installed on, size, & version.

What is the correct syntax of a command that will display all this information?
0
OS: AIX shell:ksh

i need a grep statement to give any  error for today's date and for specific time from a log file.

My grep statement should grep current date i.e. 7/19 and timing for 6 to 6:59 and finally for string as 'error' or 'Error'

e.g  log file content will be like

[7/19/17  6:01:26:611 CDT] XXXXX  error -911
0
I need to replace one of the tag attribute value from one file to other xml file. we need to update "0 58 40 * * ?" from ServiceContext.xml_pre_455 to ServiceContext.xml. we don't have xmlstarlet.

ServiceContext.xml_pre_455

<bean id="service_TriggerOfflineDBProducer" class = "org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref local="service_OfflineDBProducerJob" />
        </property>
        <!-- Schedule OfflineDB producer at 3:30 everyday, preferably after DIMP runs. -->
        <property name="cronExpression" value="0 58 40 * * ?" />
    </bean>


ServiceContext.xml

<bean id="service_TriggerOfflineDBProducer" class = "org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail">
            <ref local="service_OfflineDBProducerJob" />
        </property>
        <!-- Schedule OfflineDB producer at 3:30 everyday, preferably after DIMP runs. -->
        <property name="cronExpression" value="0 26 15 * * ?" />
    </bean>
0
I need to convert all files in a folder from binary named zone format to text zone format.

the command is

 named-compilezone -f raw -F text -o myzone.ch.hosts.text myzone.ch myzone.ch.hosts.binary

the present binary files are always named like "myzone.ch.hosts" - after conversion they should have the same name.

but how do i do that automatically for all files in the folder?

Thanks!
0
I have this rather simple shell script below and I see an error on line 8 below

What is wrong with my shell script?

set -x
for i
do
        echo $i
        outfile=$i_new
        echo $outfile
        cat $i | sed -e 's/STASIS //'   > $i_new
done
++ for i in '"$@"'
++ echo file1.xml
file1.xml
++ outfile=
++ echo

++ cat file1.xml
++ sed -e 's/STASIS //'
./removeStasis.sh: line 8: $i_new: ambiguous redirect


Here is my script:

set -v
set -x
for i
do
        echo $i
        outfile=$i_new
        echo $outfile
        cat $i | sed -e 's/STASIS //'   > $i_new
done
0
Hello,
with openldap you can define a max-password age: pwdMaxAge
Any ldap account that uses a password that was set before today-pwdMaxAge (in seconds) is considered expired.

Now on http://techadminblog.com/send-password-expiry-warning-openldap/

there is a script that can be run with crontab checking all ldap accounts and informing the affected users of an impending password expiry.

It checks if there are 3,2,1 today days left.

if [ "$DIFF" == `expr $MAXPWDAGE - 3` ]; then
 SUB="User $USERID password expire in 3 days"
 smail
 elif [ "$DIFF" == `expr $MAXPWDAGE - 2` ]; then
 SUB="User $USERID password expire in 2 days"
 smail
 elif [ "$DIFF" == `expr $MAXPWDAGE - 1` ]; then
 SUB="User $USERID password expire in 1 day"
 smail
 elif [ "$DIFF" == "$MAXPWDAGE" ]; then
 SUB="$USERID password will expire today at $EXTME UTC"

----
How can I change that part of the script  to inform the users that a password change is needed in less than 20 days, less than 10 days, today, or even has already expired?

does change "$DIFF" == `expr $MAXPWDAGE - 3` ->  "$DIFF" -lt  `expr $MAXPWDAGE - 20` the trick?

Reason we use openldap to handle external user accounts that are rarely used so informing the users that their pasword will expire in 3 days is too late - in most cases the password is often already expired when they call us about being unable to logon to our systems.

regards,
Tolomir
0
On Demand Webinar: Networking for the Cloud Era
LVL 9
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Hello,

  I would like to know if there is a way to create a Symlink-like file but with the difference that the file it points to gets executed when the link is read and the output is what I get from reading it.
  It should work on freebsd/linux.

Thanks

Best regards
0
We currently operate within a Citrix environment and publish a number of web applications by point to Internet Explorer with the corresponding website as the parameter.

We face an issue currently whereby if the browser is closed, the session remains active.

We need the session to logoff if the browser is closed.

With a previous version of IE (8 perhaps, but not entirely sure) we scripted this, however in current versions of IE this no longer works.

I guess a script that launches IE, and then monitors for its closure before issuing a logoff command would be ideal, but am open to alternative suggestions if there are better ways to achieve what we are looking for.
0
I have few excel and .rpt file which are updating daily basis, in my scenario i have to parse the files and some of the columns should be insert into MS access database. i am not sure how to start with. As per my manager i should use shell scripting to write the code but i am not sure which is the best way.

I need help in this any kind of help will be appreciated.
0
Hello Experts,

I have created an EFS Filesystem, I am trying to find a script which will give me the below

Input to script : EFS Filesystem ID
Output : {AZ targetIPAddress}

we dont have aws dns, so we are manually mounting using IP address...Here are the steps, I have...

1. The below command will give the Subnet and IP address
# $ aws efs describe-mount-targets --file-system-id fs-e10c82b2 --query 'MountTargets[*].[SubnetId,IpAddress]' --output text
OUTPUT : {SUBNET IPADDRESS}

2. The below command will give me AZ for the subnets
$ aws ec2 describe-subnets --subnet-ids subnet-9456320b --query 'Subnets[].AvailabilityZone' --output text
INPUT :SUBNET
OUTPUT : AVAILABILITY ZONE

How do I combine these 2 scripts to get
- AVAILABILITYZONE IPADDRESS

Please assist
0
I heard iOS is tailored from FreeBSD so I'm hoping to be able to do something like
"ps -ef |grep email_client_process"
if it's not there, then restart it.

Reason is our MobileIron email+ client kept getting killed by iOS as iOS sees it
as a 3rd party/foreign process.

any chance of doing this on an MDM controlled device?
0
how to execute "at unix command" in remote server via SSH or any other mean (using shell script)
0
need to send html mail body as mail using shell script in AIX
0
Hi ,
 
Can someone help here in this script:-It is throwing error:-



ORACLE_HOME=/opt_local/oracle/product/V10.2.0;export ORACLE_HOME
export PATH=$PATH:$ORACLE_HOME/bin
sqlplus -s "crm702_data/crm702_data@(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST=ariel.kpno.be)(PORT=1510)))(CONNECT_DATA =(SID=EPNYPRD)))" << EOF
for reference_code in `cat Mark_Obsolete.txt | tr " " "\n"`
do
@Mark_Obsolete.sql $reference_code
done
EOF
echo "done"




graffias:> more Mark_Obsolete.txt
1000333 1009398 1028828


SP2-0734: unknown command beginning "for refere..." - rest of line ignored.
SP2-0223: No lines in SQL buffer.
SP2-0223: No lines in SQL buffer.
SP2-0042: unknown command "do" - rest of line ignored.
Enter value for 1: done : NOT A VALID SALES ORDER REFERENCE
done



Can some one give me a format where i read the text file and transalte all orders in new line and then my sql script will use argument one by one from that text file.
0
I am looking for a command that will tell me in the whole host if I have the rights to the entire file system , if any files have changed in the last one minute or 5 minutes

I thank you very very much in advance and will reward pts right away !!!!
0
Want to be a Web Developer? Get Certified Today!
LVL 9
Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

I've never used Powershell to run scripts before so be gentle, this scripting stuff is very new to me :)

I just copied what I thought would be a very handy script from a Microsoft article that I saved as PatchScript.ps1, but when I try to run it in Powershell, I get the error:

File C:\1\patchscript.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:21
+ c:\1\patchscript.ps1 <<<<
    + CategoryInfo          : NotSpecified: (:) [], PSSecurityException
    + FullyQualifiedErrorId : RuntimeException

I looked into signing and it seems like such a long winded process to go through just to run the occasional script I'm confident will be safe, so was wondering if there is an over-ride of some sort to run an occasional self created script?  

Or is there an easy way to temporarily disable the policy preventing the execution of scripts, and then re-enable that policy immediately afterwards to maintain the security that it provides?

Your help would be appreciated.
0
Hi Experts, how to pass (ignore) below line in regex. I'm  trying to achieve this in jenkins log parser plugin.

# Should pass
chmod: cannot access './config/temp_bkp_24072016/resources': Permission denied

# Should fail
chmod: cannot access './config/resources_bkp_24072016/resources': Permission denied

#regex rule. which I'm trying to handle above two scenario
warning /^(?!.*(temp_bkp))(.*Permission denied.*)$/

Open in new window



Thanks in advance
0
Hi experts,

I'm using grep inside a function by passing search string and log file to search for the string.
I call this function few times inside my bash script

This issue is, when no match found grep terminates/error out and it not processing further.

Sample
function printSummary ()
{
    local search_string="$1"
    local job_log="$2"

    grep  -irn -B 3 -A 3 "${search_string}" ${job_log} >> ${tmp_file}
}


printSummary 'unable to' /tmp/log #if string not found, it should continue to next two strings. but it error out here.
printSummary 'error at' /tmp/log
printSummary 'ORA-' /tmp/log

Open in new window



Thanks in advance.
0
hi All,

kindly help me to write a shell or python script to delete the weblogic files. The files are rotated but need to be deleted which are 30 days old. the find command doesn't delete the files because the number of files are huge.

below is the  .logs format of the weblogic servers
/wls1034/Middleware/user_projects/domains/Domain/servers/server3/logs/

server3.log00585
 server3.log00586
 server3.log00587
server3.log00588
server3.log00589
server3.log00590
server3.log00603
server3.log00604

server3.out00035
server3.out00034
server3.out00036
server3.out00037
0
The original filename is "test.txt".
The requirement is to append the date + Timestamp (format yyyymmdd_hhmmssmsi.txt) at the point the file "test.txt" is generated.


yyyy - year
mm - month
dd - day
ss - second
msi - milli-second
0
Hi,
I am very new to shell scripting and i want to do following
read a xml file to extract value of <not_matched> tag,
from each of <SQL_Analysis>,<Data_Analysis>,<Graph_Analysis>,<Excel_Analysis>,<Pdf_Analysis> tags and compare it against a some value and depending on the result say Pass or Fail.

Any help much appreciated.

XML file as below :
<Execution_Stats>
      <Total_Executions>1</Total_Executions>      
      <Total_Errors>0</Total_Errors>
      <SQL_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </SQL_Analysis>
      <Data_Analysis>
            <NOT_COMPARED>0</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>1</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Data_Analysis>
      <Graph_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Graph_Analysis>
      <Excel_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Excel_Analysis>
      <Pdf_Analysis>
            <NOT_COMPARED>1</NOT_COMPARED>
            <MATCHED>0</MATCHED>
            <NOT_MATCHED>0</NOT_MATCHED>
            <ERROR>0</ERROR>
      </Pdf_Analysis>
</Execution_Stats>
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.