Using LIKE in a shell script

I would like to use a 'Like' and wildcards in a shell script. Something like
If $F1 like '*ABC*' then
xxxx
What would the correct syntax for this be?
Thanks!

You could do:
if [ ! -z "`echo ${F1} | grep "ABC"`" ] then
fi

Similar Messages

  • Trying to run program off network location using GPO with Power shell script.

    Hello All,
    Not much of a script writer. I am giving it a shot.  My issue is that I need to run a application update across our network and I am trying to do it with as little hands on as possible. So I was planning to push a GPO with a power shell script in it
    to run the program with elevated privileges. 
    Little background:
    We are running on a domain and end users do not have admin rights.
    The application is stored on a share on our network that is open to all domain users.
    The installer user name and password is a temp one and will only be valid for the 30 min window when everyone logs in at the beginning of the day.
    So this is what I have so far.
    $username = "USER"
    $password = "PASSWORD"
    $credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
    Start-Process PSQLv11Patch_Client_x86.msp -Credential ($credentials) -WorkingDirectory \\Server\Folder\Folder1\Folder2\filder3\PSQLv11sp3_x32\
    But for some reason I keep getting :
    Start-Process : This command cannot be run due to the error: The system cannot find the file specified.
    At line:10 char:1
    + Start-Process PSQLv11Patch_Client_x86.msp -Credential ($credentials) -WorkingDir ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
        + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
    Any help you could give would be great.
    Thanks,
    jdfmonkey

    Hi jdfmonkey,
    Has anyone provided an answer to your original question?  I am trying to use Start-Process to launch a process using another logged in user's credentials, and am not able to get it working:
    $cred=Get-Credential
    start-process Process.exe-WorkingDirectoryC:\Scripts-Credential$cred
    I get the same error that you mentioned:
    start-process : This command cannot be run due to the error: The system cannot find the file specified.
    At C:\Scripts\Process.ps1:2 char:1
    + start-process Process.exe -WorkingDirectory C:\Scripts -Credential ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Start-Process], InvalidOperationException
        + FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
    When I leave off the credentials:
    start-processProcess.exe-WorkingDirectoryC:\Scripts
    It works correctly.  Does anyone have a solution to make this work correctly?
    Please ask your own question.  You issue is nothing like the current thread.  You clearly are using a user account that has no access to the folder.  It is a permissions issue.  It is not a scripting issue.
    If you need further help please start your own question.
    ¯\_(ツ)_/¯

  • Use of expect in shell script

    hi all ,
    can anyone explain me this script particularly why expect is used here.
    set timeout -1
    spawn sftp [email protected]
    match_max 100000
    expect -exact "Connecting to 11.11.1.34...\r
    sftp> "
    send -- "cd /opt/app/policies/data\r"
    expect -exact "cd /opt/app/policies/data\r
    sftp> "
    send -- "get potcontrol.dat\r"

    "expect" is a particularly useful scripting tool when you need to make a script that performs an interactive, multi-command dialog with another utility, like FTP or SFTP (or in the olden days, I used it a lot with Kermit).
    In your example, "expect" is being used to launch the sftp client to connect to some sftp server, switch to a certain directory and then fetch a copy of a certain datafile, all while expecting precise return strings coming back from the sftp client.
    Certain tools and apps, like ftp, sftp and others, cannot be simply scripted via ordinary shell script methods to feed strings of commands to those tools and apps, because of unusual ways in which they open up their own separate /dev/tty to interact with the command line user, hence "expect" was created and is very useful for scripting dialogs with such tools and apps.
    For instance, if you tried to make a typical "here document" type of shell script like this:
    #!/usr/bin/sh
    ftp <<END_CMDS
    open some.ftp.host
    myuser
    mypassword
    cd /some/dir/path
    get somefile.dat
    bye
    END_CMDS
    exit 0
    You'd find that a typical ftp client will not read the commands from the shell script's /dev/tty and will still try to interactively prompt for user, password, etc. or it might just hang indefinitely waiting for input that will never come to it.
    There are other shell scripting tricks to get a "here document" script to function with utilities like ftp/sftp/others, but if you have "expect" installed on your system, it's very simple to run "autoexpect" to record an interactive session of what you want to do, which will then automatically create the "expect script" for you.
    "Expect" was created by our (USA) tax dollars, and is free for anyone to use: See the home page here for the whole story: http://expect.nist.gov/

  • Using fsch inside a shell script?

    I like the premise of using fsch because build times are
    greatly reduced. However, I want to integrate fsch better into a
    more automated build system, even Ant. Anyone know how to do this?
    BTW, I'm using a Unix based system: Mac OS X. I guress I'd like to
    be able to call something more like 'fsch mxmlc .....'
    I have played with the Flex apache module of Flex 3 but
    ultimately want any build error to appear back in my text editor
    inside of inside the browser. So I have the apache module working
    well but am now trying to get fcsh to work inside a shell script as
    a single call - how do I call out to the running process?
    Thanks,
    Phil

    You could do:
    if [ ! -z "`echo ${F1} | grep "ABC"`" ] then
    fi

  • How to use encoded password in shell script ?

    Hi everybody,
    For make a load file in oracle table, I'm using a LKM File to Oracle updatding with a sqlldr (shell script).
    My problem is very simple : For security reason in this shell-script , I don't want to see in clear the password of the Oracle user for database connection. Is it possible and how do it ?
    Thanks in advance

    Hi-
    Yes it is possible by the way of KM custamization, You need to modify LKM call sqlldr via jython step to pass the user info and password as variable instead of ODI method. Try this command in your KM step:
    userid=#GLOBAL.user/#GLOBAL.psw
    Hope this will work for you.
    Thanks,
    Saravanan Rajavel

  • Use Launchd to run shell script at boot

    Hello
    I'm trying to create a plist file that will run a shell script at bootup of the server.
    I have the following xml so far in the plist file:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Disabled</key>
    <false/>
    <key>Label</key>
    <string>com.apple.mymount</string>
    <key>ProgramArguments</key>
    <array>
    <string>/mount-script/./mount.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    </dict>
    </plist>
    The shell script is just a mount command:
    #!bin/sh
    #MOUNT folder X ON server Y
    sudo -u _www mount_smbfs -f 777 -d 777 //username:password@server/folder /mnt/mount
    The shell script works fine from the terminal.
    I can see the plist has loaded after bootup but the script doesn't run.
    What am I doing wrong?
    Would need some help please!

    First problem:
    <string>com.apple.mymount</string>
    com.apple is (or at least should be) reserved for Apple scripts, not your own. This should be renamed to your own domain (or your own name if you don't have a domain).
    In addition the .plist file name should match (so if you rename the script Label to be 'com.my.mount' then the .plist should be com.my.mount.plist. You don't include the file name in your post to know if you're already doing that.
    Second:
    <string>/mount-script/./mount.sh</string>
    What? That looks wrong to me. Of course, it could be right, but the '/./ in the middle worries me, so I just can't think it is.
    Where is the script, really?
    Third:
    sudo -u _www mount_smbfs -f 777 -d 777 //username:password@server/folder /mnt/mount
    No. Never use 'sudo' within a launchd task. If you need the task to run as a different user then use the launchd keyword UserName to specify that username:
    <key>UserName</key>
    <string>_www</string>
    I can see the plist has loaded after bootup but the script doesn't run.
    If none of the above fixes it then look at the logs and tell us what it has to say. /var/log/system.log

  • Loading incomplete using sqlplus_exec_template.sql  in shell script

    Hi,
    I've tried to automate the dataloading by calling sqlplus_exec_template.sql for each mapping in the shell script bash. (I comment out the last exit line in the script). But the loading were always partially complete for those that take longer time, says more than 5 or 10min. I've also tried to call each mapping in different shell and got the same result. How do you work around this? Below is part of the lines in my shell script. Thanks.
    sqlplus -s test_rta/test_rta << EOF
    @sqlplus_exec_template.sql 'TEST_RTR' 'TEST_LOC' 'PLSQL' 'CONSOL_SUP_MAP' ',' ','
    @sqlplus_exec_template.sql 'TEST_RTR' 'TEST_LOC' 'PLSQL' 'CONSOL_PART_MAP' ',' ','
    EOF

    I 've tried to use :
    sqlplus username/[email protected] @C:\OWB\owb\rtp\sql\sqlplus_exec_template.sql
    rtschema OWBLOCATION SQL_LOADER CRD_APPL_MAPPING "," ","
    where OWBLOCATION I have used the deploy location of the mapping for my case, created within OWB. The value is CCS_DEPLOY.
    But the error is the same :
    ======================================================
    Stage 1: Decoding Parameters
    | location_name=CCS_DEPLOY
    | task_type=SQL_LOADER
    | task_name=CRD_APPL_MAPPING
    Stage 2: Opening Task
    declare
    ERROR at line 1:
    ORA-20001: Task not found - Please check the Task Type, Name and Location are
    correct.
    ORA-06512: at line 261
    ========================================================
    could you tell me the SQL used by WB_RT_API to get the task from runtime schema. So that I could check the correct location myself.
    Or how could I view the pl/sql of WB_RT_API_EXEC which is wrapped.
    Thx for your help.
    Rg.
    CH

  • How to use CONCSUB program in shell script program

    I have to write a shell script which will further call the concurrent program.
    My concurrent program is having 3 parameters. Plz send some suggestion
    R's
    Vijay

    Pl use the search feature to locate threads that have discussed this issue before. Some examples -
    Re: modify .out file
    Re: shell script using CONCSUB utility
    HTH
    Srini

  • I am trying to use automator to make a simple app that when I open it, it comes up with a dialog box that asks for a link that you want to download. and it will download it for you using the curl -O shell script in Terminal. How would I do it?

    I want this so I can just download anything I want by just having the link and I have made a few things with shell scripts in automator before, just never anything where i need to input a value into the shell script.

    Easy:

  • How to run shell script using External Process in Process Flow?

    Hi,
    We can run external process using Process flow.
    I would like to run shell script as external process in Process flow.
    Could any one please explain it?
    Thanks and regards
    Gowtham Sen.

    HI,
    As you said I tried this case. I got the following error. The script is running successfully while I tested at unix command prompt.
    The error is as follows..
    tarting Execution PFPS_SMPL_RUNSHELL
    Starting Task PFPS_SMPL_RUNSHELL
    Starting Task PFPS_SMPL_RUNSHELL:EXTERNALPROCESS
    /SOURCE_FILES/CollectFiles.sh: line 1: ls: command not found
    /SOURCE_FILES/CollectFiles.sh: line 1: wc: command not found
    /SOURCE_FILES/CollectFiles.sh: line 1: ls: command not found
    Completing Task PFPS_SMPL_RUNSHELL:EXTERNALPROCESS
    Starting Task PFPS_SMPL_RUNSHELL:EXTERNALPROCESS_1
    SQL*Plus: Release 10.1.0.2.0 - Production on Fri Sep 29 22:57:39 2006
    Copyright (c) 1982, 2004, Oracle. All rights reserved.
    ERROR:
    ORA-12545: Connect failed because target host or object does not exist
    Enter user-name: SP2-0306: Invalid option.
    Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
    where <logon> ::= <username>[<password>][@<connect_identifier>] | /
    Enter user-name: SP2-0306: Invalid option.
    Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
    where <logon> ::= <username>[<password>][@<connect_identifier>] | /
    SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
    Completing Task PFPS_SMPL_RUNSHELL:EXTERNALPROCESS_1
    Completing Task PFPS_SMPL_RUNSHELL
    Completing Execution PFPS_SMPL_RUNSHELL
    My scenario is---
    I am trying to return a file name from one shell script. I created a external process for that. After completion of this process, I am running another script which takes that file name and trying to create a external table. The both scripts are runnning successfully. But while I am trying to run using process flow, its not coming.
    And I am not getting the way to catch the output of external process and pass it as parameter as another external process.
    Any suggestions are welcome.
    Thanks and regards
    Gowtham Sen.

  • Shell script in Applescript

    I have a program that I run via Terminal, but I don't want a terminal window open while I run it (Just personal preference). I have an applescript set up to run the Terminal command, but the thing is that the command is "on" while the program is running, Is there some way that I can have the command go and then end the script wihtout closing the program? Or am I out of luck and have to have the Terminal window open?
    The program I am using is located here http://sites.google.com/site/sc2gears/
    Thanks for the help!

    The program is distributed (according to the docs) as a .command file, so you can get the efect you want like so:
    do shell script "/Users/yourname/further/path/Sc2gears-os-x.command &> /dev/null &"
    the &> /dev/null tells applescript that you don't care about any output, so it moves on to the next command, and the closing & sets the process up as a standalone.  Note:
    If the process doesn't close itself automatically you'll need a separate way of doing that
    if the process produces output you want to keep, don't use /dev/null - use an appropriate file path
    (obviously) '/Users/yourname/further/path' needs to be replaced with the correct path to the command, and needs to be single-quoted/escaped if it contains spaces or other unix-confounding characters

  • How to tell if item is a folder or volume with applescript or shell script?

    I am working on a service in Automator that will eject the selected drive when it is finished. Unfortunately automator can only tell the difference between files and folders for the service menu.
    Im wondering if if i can use an applescript or shell script that would check if the selected folder is a volume or folder and quit the action if its a folder. I figure the best way to do this is have it determine if the items path is in /Volumes/, but i am completely new to the process and have no idea how to do this.
    My automator workflow looks like:
    Ask for Confirmation
    Get Selected Finder Items
    Shell Script
    I have the path of the folder selected being passed into the shell script, but after its in there i dont know how to determine if its a volume or not.
    Thanks!

    K T,
    I completely missed that section of the forums, sorry
    Neil,
    I had that kind of script set up but it was like this:
    on run {input, parameters}
    tell application "Finder"
    kind of item parameters
    end tell
    end run
    And i just figured out that i had to change the first line to "on run {parameters}" and now it works great.
    Thanks for the help, it got me going in the right direction

  • Displaying an alert (Applescript or otherwise) from shell script?

    I have a point in a shell script where I'd like to put up an alert dialogue on a particular error condition. The script runs in the background and doesn't have a terminal window. I tried writing a little applescript that uses the applescript alert command and call it using osascript from my shell script, but it doesn't work. If I enter "osascript ~/myscript.scpt" in a terminal window, I get the error message "/Users/Ted/myscript.scpt: execution error:No user interaction allowed. (-1713)" (If I run myscript.scpt from the script editor it does what I want it to do.) Any ideas? I suppose I could have my shell script create a file in some folder and have my applescript be triggered as a folder action, but that seems pretty roundabout!

    Thanks -- I apologize for not doing a more thorough search! Yes, that comes very close to addressing my need, but I have run into one difficulty. If I run my shell script from the terminal (pasting it in) everything works fine. If I run it as a packaged app (with Platypus) everything works like it's supposed to, except that the alert applescript (it's just a one line script) briefly flashes the alert dialogue when it's supposed to and then dies, rather than waiting 10 seconds or until I click OK. I'll have to experiment and see if I can tell what's going on.

  • How to avoid password prompt in shell script for zip password protection

    Hi
    I am trying to set password protection to my oracle database export backup. Once the backup completed, it should compress with a password protection. Thats the plan. Initialy we were using the gzip for the compression. Then realized that there is no password protection for the gzip. Started using zip option. I tried using
    zip -P <password> filename
    But it was throwing below error.
    -bash-3.2$ zip -P expreports REPORTS_2013FEB14.dmp
    zip warning: missing end signature--probably not a zip file (did you
    zip warning: remember to use binary mode when you transferred it?)
    zip warning: (if you are trying to read a damaged archive try -F)
    zip error: Zip file structure invalid (REPORTS_2013FEB14.dmp)
    Not quite sure why.
    Then I used zip -e REPORTS_2013FEB14.dmp.zip REPORTS_2013FEB14.dmp
    But this prompting for the password. As I am trying to put the command in the script. It will be tough if it prompts for the password.
    I would like to know how to avoid the password prompting by saving somewhere or how the code should be written. Tried using expect feature of shell script. Below was the code I tried. It didnt work.
    [oracle@SF40V6636 test]$ cat repexp.sh
    zip -e REPORTS_imp.log.zip REPORTS_imp.log
    expect "Enter password:"
    send "imprep"
    expect "Verify password:"
    send "imprep"
    So please help in avoiding this password prompt or let me know how to change the code.
    Thanks
    SHIYAS M

    How about using gpg and adding a secret key to the requirement of a password? No one should be able to decrypt your file, not by knowing only the password.
    1. Generate a public and private key pair:
    $ gpg --gen-key
    When it shows "We need to generate a lot of random bytes…" open another terminal session and type "dd if=/dev/sda of=/dev/null" to create traffic. When the public and secret key created and signed you can Ctrl-C the dd command.
    To see what you have created:
    $ gpg --list-keys
    2. Encrypt and gzip your stuff:
    $ tar zcf stuff.tgz file_or_folder
    $ gpg recipient "Some Name" encrypt stuff.tgz
    $ rm -f stuff.tgz
    3. Decrypt and extract the archive:
    $ gpg batch yes --passphrase "password" -d stuff.tgz.gpg > stuff.tgz
    $ tar zxvf stuff.tgz
    Again, knowing the password alone will not let anybody decrypt your stuff.

  • Update command in Shell script

    Hi friends
    sqlplus -s / <<END
    set feedback on;
    update tran2 set sno=1;
    exit;
    END
    when i am using update command in shell script like above
    it is updating the database well...but i just want to know how many rows it is updating and i dont want to commit
    for that
    sqlplus -s / <<END
    set feedback on;
    update tran2 set sno=1;
    set feedback off;
    rollback;
    exit;
    END
    It's working fine
    is there any other method to do the same

    Well what's exactly your requirement? The current requirement doesn't make a lot of sense.
    How many row is going to be updated depends on where clause, if you have no where clause that essentially updating whole table, the number of row updated is count of your rows.

Maybe you are looking for