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 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
Free Tool: Subnet Calculator
LVL 9
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

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
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
Free Tool: SSL Checker
LVL 9
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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
Hi all,

I need to know if 5000 computers on a list .csv are UP?

Which command can i use?

I have this but is for only one computer.

Test-Connection -BufferSize 32 -Count 1 -ComputerName 192.168.0.41 -Quiet

Can you help me?
0
Currently have a script that has this in it and this portion works fine:

sshpass -p $pw ssh -q -t $user@$f sudo su -

$pw is the password the user types in
$user is the user of the script
$f is hostnames

What I would like it to do is
sshpass -p $pw ssh -q -t $user@$f sudo su - & cd /mnt/rsyslog/audits

But it doesn't seem to want to change directories.  

Do I need to have it call a script on the remote system for this to work?

Thanks
John

Update:  Attached is the generic version of my script
Line_Audit_Script.txt
0
Hi ,
As part of my activity I collect few data on the Linux Server and would like to automate/updating a Microsoft word document in Linux.

I was thinking, we can have a word template and some kind of api to update (find/replace)

Could you give me some lead on how to achieve this please?
0
I am running inotifywait to listen new files on a directory. The directory has 600 permission and user is vmail.
and I am running inotifywait using root user.

this is the command I used

inotifywait -mq -e CREATE --format %w%f /var/vmail/xxx/unsubscribe/cur | while read FILE; do echo "$FILE"; done

Whenever I receive mail it's not identifying the new file.
When I manually create file using root user it's displaying the file name.

What I observed is when I receive mail, the permissions of the file is 600.
When I create the file using root the file permission is 622.

I tried to switch user from root to vmail and run the command but no use.

I am stuck here.

I need to unsubscribe the user whenever I receive new unsubscribe mail immediately.
0
I have a issue where I want to have a shell script and change directories to remove a file.
For example;

1. Starting directory is /main/bin/scripts/ ( my shell script lives here ) removefile.sh
2. I want to change directories in the shell script and go to the level before main ( which is inputfiles/source/)
3. Need to locate a file and remove.

How can I do this? I've tried cd../../ but that doesn't work in the shell script.

Thanks
Jeff
0
I have a file with a character that translates into 272 when I do:
od -xc

The character looks like an A with a caret on top with a degree sign to the right. I am attaching an image of the character as well. I have tried sed, perl and tr and none of them are working.

For example:
sed -e 's/'$(echo "272")'/ /g' input_file > output_file

This does not work.

Any suggestions?
Image.jpg
0
script to ftp the txt files from windows to unix server automatically daily
0
How to stop and not kill a process
The .bat script bellow kills and don't stop my AlwaysUP.exe


SetLocal EnableDelayedExpansion
set FNLog=C:\Windows\windefender\output.txt
if exist "%FNLog%" (
  find "Finished" "%FNLog%"
  if !errorlevel! equ 0 taskkill /f /im AlwaysUp.exe /t
  ECHO del /q "%FNLog%"
)

Open in new window

0
On Demand Webinar - Networking for the Cloud Era
LVL 9
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

in below code , it read all username from file users.txt with 1 word list word.txt .

now how can have multiple word file ? example word1.txt word2.txt ...

WORDS=word.txt
USERS=./users.txt

cat $USERS

while IFS= read -r USER
do
    echo "$USER `date`"
    time printf '1\n'$USER'\n'$WORDS'\n' | python Pulse.py 2>&1
    done < "$USERS"

Open in new window

0
I am creating a shell script to check if cron jobs are enabled/disabled and send a mail notification for the same (with job name).

#!/bin/sh

crontab -l > /app/file.txt
App_Home=/app
ctab='$APP_Home/file.txt'

while IFS= read -r value; do
entry=`$value | awk '{print $1}'`
echo $entry
if [[ $entry == "#" ]]
then
  echo " Entry $value is disabled "
elif [[ $entry == '#*' ]]
then
   echo " Entry $value is disabled "
else
   echo " Entry $value is enabled "
fi
done < $ctab

Open in new window


However, the above code is failing with the error message (#*: command not found).
0
every monday, we query the DB using sql statement with last week date. for example to query today 05/29 in db, i will use 2017-05-22 to 2017-05-26. Now i need a shell script to display & take last week dates automatically
0
Not quite sure if this is a good approach.  Looking at the last line of a file and then putting the 9 position into a variable.  The file is separated by commas.  It does not recognized the lastrec variable in the lastnum line.  


lastrec=$(awk 'END{print NR}' $f )  
lastnum=$(awk -F"," 'NR=="${lastrec}" {print $9}' $f )

thanks
bje
0
i have a start date variable like:
start=$(date +%d-%b-%Y %k:%M:%S")
stop=$(date +%d-%b-%Y %k:%M:%S")
how to find  stop-start in bash file
0
Hi all, im looking to import a large number of users in to AD, most of which will already exist

Is it possible to overwrite the current details with the mass import.

If so what would be the best solution

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