Shell script that captures key input? (keylogger)

I want to record all my keystrokes, just to see the frequency of some keys. There is a bunch of keyloggers on google that captures keystrokes, but none that is good and is in the AUR. Isn't it possible to do just with a little shell script? I don't mind if i have to keep the terminal open, and there is no need for any daemon/advanced stuff. Could you record a /dev/something or similar?

Haha, check this out: (cursor=move, z=fire, q=quit)
#! /usr/bin/python
from curses import *
import threading
class ckeylog( threading.Thread ):
def run(self):
file=open("/dev/input/event1","rb")
keymap={
'\x2c': 'z',
'\x2d': 'x',
'\x2e': 'c',
'\xc8': 'UP',
'\xd0': 'DOWN',
'\xcb': 'LEFT',
'\xcd': 'RIGHT',
'\x10': 'q',
'\x11': 'w',
'\x12': 'e',
'\x01': 'ESC',
'\x2a': 'LSHIFT',
'\x1c': 'ENTER',
self.loop=True
while self.loop:
event=file.read(48)
if event[28] == '\x01':
state=True
elif event[28] == '\x00':
state=False
else:
continue
if event[12] in keymap:
self.map[keymap[event[12]]]=state
file.close()
def quit(self):
self.loop=False
keylog=ckeylog()
keylog.map={}
keylog.start()
def main(s):
curs_set(0)
ship=[
"| /\ |",
"+/!!\+",
shipx=0
shipy=0
bullet="* *"
bulletx=0
bullety=0
fire=False
while True:
(my,mx)=s.getmaxyx()
if 'q' in keylog.map:
if keylog.map['q']: keylog.quit(); return
if 'UP' in keylog.map:
if keylog.map['UP']: shipy=shipy-1
if 'DOWN' in keylog.map:
if keylog.map['DOWN']: shipy=shipy+1
if 'RIGHT' in keylog.map:
if keylog.map['RIGHT']: shipx=shipx+1
if 'LEFT' in keylog.map:
if keylog.map['LEFT']: shipx=shipx-1
if 'z' in keylog.map:
if keylog.map['z']: (fire,bullety,bulletx)=(True,shipy,shipx)
if shipy<0: shipy=0
if shipy>my-len(ship): shipy=my-len(ship)
if shipx<0: shipx=0
if shipx>mx-len(ship[0]): shipx=mx-len(ship[0])
if fire and bullety == 0: fire=False
if fire: bullety=bullety-1
s.erase()
s.addstr(shipy,shipx,ship[0])
s.addstr(shipy+1,shipx,ship[1])
try:
s.addstr(shipy+2,shipx,ship[2])
except error: pass
if fire: s.addstr(bullety,bulletx,bullet)
s.refresh()
napms(10)
wrapper(main)

Similar Messages

  • A script that captures the coordinates of the mouse clicks and saves them into a file

    Hello,
    I'm trying to create a cartoon taking a movie (I've chosen blade runner) as base. I've got the real movie and I've exported all the pictures using VirtualDUB. Now I have a lot of images to modify. I would like to modify the actors faces with the faces generated by Facegen modeller. I'm thinking how to make the whole process automatic because I have a lot of images to manage. I've chosen to use Automate BPA,because it seems the best for this matter. I'm a newbie,so this is my first attempt using Adobe Photoshop and Automate BPA. I wrote a little script. It takes a face generated with Facegen modeller and tries to put it above the original actors faces. But it doesn't work very good and I'm not really satisfied,because the process is not fully automated. To save some time I need to write a script that captures the coordinates of the mouse when I click over the faces and that saves them into a file,so that Automate BPA can read these coordinates from that file and can put the face generated with Facegen Modeller above the original face. I think that Automate BPA is not good for this matter. I think that two coordinates are enough,X and Y. They can be the coordinates of the nose,because it is always in the middle of every face. It is relevant to knows how big should be the layer of the new face,too. This is the Automate BPA code that I wrote :
    <AMVARIABLE NAME="nome_foto" TYPE="TEXT"></AMVARIABLE>
    <AMVARIABLE NAME="estensione_foto" TYPE="TEXT"></AMVARIABLE>
    <AMSET VARIABLENAME="nome_foto">br</AMSET>
    <AMSET VARIABLENAME="estensione_foto">.jpeg</AMSET>
    <AMVARIABLE NAME="numero_foto" TYPE="NUMBER"></AMVARIABLE>
    <AMVARIABLE NAME="coord_x" TYPE="NUMBER"></AMVARIABLE>
    <AMVARIABLE NAME="coord_y" TYPE="NUMBER"></AMVARIABLE>
    <AMWINDOWMINIMIZE WINDOWTITLE="Aggiungere_layer - AutoMate BPA Agent
    Task Builder" />
    <AMWINDOWMINIMIZE WINDOWTITLE="AutoMate BPA Server Management Console
    - localhost (Administrator)" AM_ONERROR="CONTINUE" />
    <AMENDPROCESS PROCESS="E:\Programmi_\Adobe Photoshop
    CS5\Photoshop.exe" AM_ONERROR="CONTINUE" />
    <AMRUN FILE="%&quot;E:\Programmi_\Adobe Photoshop CS5\Photoshop.exe&quot;%" />
    <AMPAUSE ACTION="waitfor" SCALAR="15" />
    <AMSENDKEY>{CTRL}o</AMSENDKEY>
    <AMPAUSE ACTION="waitfor" SCALAR="1" />
    <AMINPUTBOX RESULTVARIABLE="numero_foto">Inserire numero FOTO di
    partenza -1</AMINPUTBOX>
    <AMINCREMENTVARIABLE RESULTVARIABLE="numero_foto" />
    <AMPAUSE ACTION="waitfor" SCALAR="1" />
    <AMMOUSEMOVEOBJECT WINDOWTITLE="Apri" OBJECTNAME="%nome_foto &amp;
    numero_foto &amp; estensione_foto%" OBJECTCLASS="SysListView32"
    OBJECTTYPE="ListItem" CHECKOBJECTNAME="YES" CHECKOBJECTCLASS="YES"
    CHECKOBJECTTYPE="YES" />
    <AMMOUSECLICK CLICK="double" />
    <AMPAUSE ACTION="waitfor" SCALAR="10" />
    <AMSENDKEY>{CTRL}+</AMSENDKEY>
    <AMPAUSE ACTION="waitfor" SCALAR="20" />
    <AMSENDKEY>l</AMSENDKEY>
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSEMOVE MOVEX="429" MOVEY="281" RELATIVETO="screen" />
    <AMMOUSECLICK />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSEMOVE MOVEX="659" MOVEY="281" RELATIVETO="screen" />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSECLICK />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSEMOVE MOVEX="659" MOVEY="546" RELATIVETO="screen" />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSECLICK />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSEMOVE MOVEX="429" MOVEY="546" RELATIVETO="screen" />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSECLICK />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSEMOVE MOVEX="429" MOVEY="281" RELATIVETO="screen" />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSECLICK />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMSENDKEY>v</AMSENDKEY>
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSECLICK CLICK="hold_down" />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSEMOVE MOVEX="131" MOVEY="99" RELATIVETO="screen" />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSEMOVE MOVEX="99" MOVEY="162" RELATIVETO="screen" />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMMOUSECLICK CLICK="release" />
    <AMPAUSE ACTION="waitfor" SCALAR="2" />
    <AMINPUTBOX RESULTVARIABLE="coord_x">Inserire coordinata X</AMINPUTBOX>
    <AMINPUTBOX RESULTVARIABLE="coord_y">Inserire coordinata Y</AMINPUTBOX>
    <AMMOUSEMOVE MOVEX="200" MOVEY="200" RELATIVETO="screen" />
    <AMMOUSECLICK CLICK="hold_down" />
    <AMMOUSEMOVE MOVEX="%coord_x%" MOVEY="%coord_y%" RELATIVETO="position" />
    <AMMOUSECLICK />
    and this is a short video to explain better what I want to do :
    http://www.flickr.com/photos/26687972@N03/5331705934/
    In the last scene of the video you will see the script asking to input the X and the Y coordinates of the nose. This request is time consuming. For this reason I want to write a script that captures automatically the coordinates of the mouse clicks. The only thing to do should be click over the nose and the script should make the rest. As "c.pfaffenbichler" suggested here : http://forums.adobe.com/thread/775219, I could explore 3 ways :
    1) use the Color Sampler Tool’s input with a conventional Photoshop Script.
    2) use After Effects would provide a better solution.
    3) Photoshop’s Animation Panel might also offer some easier way as it might be possible to load two movies (or one movie and one image) and animate the one with the rendered head in relation to the other.
    Since I'm a totally newbie in graphic and animation,could you help me to explore these ways ? Thanks for your cooperation.

    These are the coordinates of the contours of the face that you see on the picture. Can you explain to me how they are calculated ? The coordinates of the first colums are intuitive,but I'm not able to understand how are calculated the coordinates of the second one.
    Thanks.
    1 COL     2 COL (how are calculated these values ?)
    307.5000 182.0000 m
    312.5000 192.0000 l
    321.5000 194.0000 l
    330.5000 193.0000 l
    335.0000 187.0000 l
    337.0000 180.5000 l
    340.0000 174.0000 l
    338.5000 165.5000 l
    336.0000 159.0000 l
    331.5000 153.0000 l
    324.5000 150.0000 l
    317.0000 154.0000 l
    312.5000 161.0000 l
    309.0000 173.0000 l
    307.5000 182.0000 l
    Message was edited by: LaoMar

  • Ways to run a shell script that starts a python script

    I have a shell script that is used to launch a python (2.5.1 installed via Fink) script (IDLE). The shell script, the IDLE script, and the python binary are all in /sw/bin as usual. This all has to be done AFTER X11 has been launched. I have to make this easy for my students to use.
    In each account's home .xinitrc file, I have the lines
    source .profile
    vpython2.5 *
    and this works, but it calls the vpython2.5 script every time X11 is launched. I've tried adding the vpython2.5 command to the X11 Applications menu, but this works ONLY if I add /sw/bin to the script name. Apparently the menu doesn't "know" about the current PATH setting. The keyboard shortcut I put in the menu neither shows up nor works either. So much for that option.
    Now I've discovered Platypus and it looked promising, but I'm obiously not using it correctly and from the documentation, I can't figure out what I'm doing wrong.
    So here's the ultimate question. Is there a way to use Platypus to encapsulate the vpython2.5 script, preferably also starting up X11, so students will only have to click on the new app's icon? This is how OpenOffice.org starts up. It seemed simple enough to do in Platypus, but I never saw the IDLE window open up.

    I added a shortcut key "j" for the "xman" app in X11, and it seems to work fine. Did you press the command key with the shortcut key? Are you sure the shortcut key you selected does not overlap with others in the menubar?
    There should be no problems creating an application with Platypus using a shell script. In my experience, you have to source all necessary files, assuming that the shell script does not recognize your terminal settings. You can also launch X11.app in the shell script with the following command:
    command open -a X11
    It is a good idea to pause the shell script until X11 finishes launching. To do this, you need a command like,
    command sleep 5
    Otherwise, if you try to start X11-dependent apps in the shell script while X11 is launching, it will fail. There may be better ways to do this.
    Hope this helps.

  • Need to call Shell script that uses SQL loader in APex4.1/11g

    Hi there!
    I have a requirement, wherein I have to call a shell script that connects to an external server, ftp's a file in and then uses sqlloader to load data into our table. Now we have the ftp script that does this for another program, but is a scheduled job. I wanted to call the ftp shell script from within APEX. Any suggestions on how this can be done, what PL/SQL logic can we use? I see online some people using dbms scheduler for this?
    Thank you
    Sun

    Hi,
    Create some sh script on your oracle host machine where you can join into external server and run the process.
    something like:
    run_external_sh.sh
    #!/bin/sh
    ssh ext_user@ext_host ./sqlloader/import/import.shThen create a external JOB to call it via ORACLE(PL/SQL)
    -- Call Shell Script.
    BEGIN
      DBMS_SCHEDULER.create_program (
        program_name        => 'external_call_sh',
        program_type        => 'EXECUTABLE',
        program_action      => '/local_host/call_external/sh/run_external_sh.sh',
        number_of_arguments => 0,
        enabled             => TRUE,
        comments            => 'Call external SH script');
    END;
    /Now you can create a scheduled/or not scheduled JOB
    -- Job defined by an existing program and schedule.
    BEGIN
      DBMS_SCHEDULER.create_job (
        job_name      => 'jb_external_call_sh',
        program_name  => 'external_call_sh',
        schedule_name => 'external_call_scheduler', -- created scheduler
        enabled       => TRUE,
        comments      => 'Job defined by an existing external_call_sh program and schedule.');
    END;
    /Now you can call the JOB in APEX in PL/SQL process.
    BEGIN
      -- Run job synchronously.
      DBMS_SCHEDULER.run_job (job_name            => 'jb_external_call_sh');
    END;Regards
    J :D

  • Applescript/shells script for capture one

    Hey,
    Wanting a script that will take the last item copied to the clipboard (which will be a folder name), search for it in finder, in "this mac", and then open the folder in Capture One.  It would be great if it were ready to run, so I could launch it each time with a keystroke.  Any one willing to help me on this.  Thanks so much!!
    I know a little applescript, but this one is kind of out of my league, I think, at least.

    Hi,
    You can use this script in an Automator Service (you can assign a keystroke combination to this service).
    If the script find one folder whose name equal the contents of the clipboard, "Capture One" will open this folder.
    if the script finds multiple folders whose name equal the contents of the clipboard, it will do nothing, because I don't know what you want in this case.
    To create a service, you start by selecting New from Automator's File menu.
    You should select the Service option, which is accompanied by a gear icon, clic "Choose" button.
    In your new service, you will see a bar at the top of the Automator flow pane. It has combo boxes that allow you to set filters that establish the conditions in which your service should be made accessible. You want to make a service that receives selected "No Input" and will operate in any application or select an application.
    Add the "Run Shell Script" action
    Copy/paste this script in the action:
    folder=$(mdfind "kMDItemFSName = \"$(pbpaste -Prefer txt)\" && kMDItemContentType = \"public.folder\"")
    if [ -z $folder ];then exit 0;fi ## no match
    tot=$(wc -l <<< "$folder")
    if [ $tot -eq 1 ]; then open -b 'com.phaseone.captureone7' "$folder"; fi
    Replace the bundle identifier in this script --> 'com.phaseone.captureone7'
    To know the bundle identifier of your "Capture One" application, run this AppleScript, copy the result to change the  bundle identifier in the shell script
    tell application "Finder" to get id of (application "Capture One")
    Save the service, quit Automator
    The final step is to assign a keystroke combination to the newly created service.
    Open the System Preferences application and navigate to the Keyboard preference pane, and select the Shortcuts tab.
    From the list on the left of the preference pane, select the Services category.
    A list of the installed services will be displayed to the right.
    Scroll to the last category titled General, and locate the service you just created.
    Double-click to the far right of the service name to activate the keystroke input field and then type the key combination you wish to assign to the service.
    Close the System Preferences application.

  • How to get name of batch file/shell script that starts program?

    I don't think there's a way to do it, but I'm asking the question anyway...
    of course, the startup script could pass its name as a parameter to the Java program, but I was wondering if the information could be determined "directly," via Java code. The idea is to allow your Java program to modify the startup configuration specified by your startup shell script.
    For example, a "startup configuration" menu item would pop up a dialog box that would display- and allow you to change- the startup parameters, and then let you write the changes back to the script file.

    There are always some ways to do things.
    I guess for your case, you need to go through JNI and have a native program to back track the Process ID of who started who. Never done that but I guess should work.
    But a more natural way to do this is to have your startup configuration stored in an xml file or a properties file inside your classpath.
    --lichu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Shell script that required password

    Hi,
    I'm using an automator script to upload some files to a remote Linux server, and I'm using rsync in an automator shell script action.
    That command required a password to work, how can I enter the password in the shell script action?
    Thanks

    Thanks for your answer, but as I'm no expert in AS,
    I'm not sure to understand your answer.
    How do those parameters are sent to AS?
    You put it in the statement:
    do shell script "rsync /source /dest" password "xyzzy" user name "you"
    You can set up a keychain for the password and retrieve it when needed, to be secure in your code. Post back or head over to AS forum, we'll help you out. http://discussions.apple.com/forum.jspa?forumID=724
    I suppose it can be run within Automator using a run
    AS instead of a run shell script. As my automator do
    some other task too.
    Yes, Automator has Run AppleScript action.
    And yes, you're right, iWeb publishing that is! Good
    guest!
    I saw some of your posts in iWeb board.
    I'm mucking around with iWeb, it's a bloated monster. There are quite a few restrictions in iWeb, I had to hand code some of the stuffs, such as meta data keywords, tricky stuffs... I'm thinking of writing a script for post production.

  • How to check from a shell script that a particular software is installed

    Hai friends
    I want to write a shell script which has to check whether a particular software is installed on the machine, or not. If installed, then what version is it using and the get the version number and which type of installer is it? i mean is it a .rpm installation or a tar.gz installation.
    how can i check this from a shell script. If any of you have any idea please give me a sample script to check this
    Thank you

    @Raja_Abilash
    I don't think this is a right thread & right forum to POST this question.
    better go ahead with forums related to LINUX.

  • Invoking a servlet from an unix shell script

    I have successfully created a servlet that when loaded via a browser takes input values in a form. After hitting "submit" the results are returned to the browser.
    Now I would like to create an unix shell script that:
    1. takes input values from the command line
    2. invokes the servlet that does the necessary processing
    3. returns the results (via echo, or in a text file, etc.)
    Please give me any clues, hints, directions on
    1. how to convert my existing servlet to accommodate a shell script
    2. how to invoke the script within the shell script
    Please refer me to any existing examples if available.
    Thanks,
    George

    Using the code below as an example I think you are saying I should take the following steps in a java sample program:
    1. in a sample program create an Testservlet object -
    Testservlet newservlet = new Testservlet();
    2. to send input to the servlet execute -
    newservlet.doGet( ? , ? );
    I'm not sure what the parameters should look like
    but I guess one of them is the input value.
    3. to get output from the servlet execute -
    String results = null;
    results = newservlet.doPost( ? , ? );
    Again, I'm not sure what the parameters
    should look like.
    public class TESTservlet extends HttpServlet
    String connPool;
    public void init(ServletConfig config)
    throws ServletException
    super.init(config);
    connPool = getInitParameter("dataSource");
    if (connPool == null) {
    System.err.println("This servlet requires a " +
    " dataSource initArg." );
    public void doPost(HttpServletRequest req,
    HttpServletResponse res)
    throws ServletException, IOException
    // first, set the "content type" header of the response
    res.setContentType("text/html");
    //Get the response's PrintWriter to return text to the client.
    PrintWriter pw = res.getWriter();
    pw.println("test");
    String testinput = null;
    try
    testinput = req.getParameter("testinput");
    catch (Exception e)
    e.printStackTrace();
    pw.println("testinput = " + testinput");
    finally
    pw.close();
    public void doGet(HttpServletRequest req,
    HttpServletResponse res)
    throws ServletException, IOException
    res.setContentType("text/html");
    PrintWriter pw = res.getWriter();
    pw.println("Test Servlet");
    putForm(req, pw);
    pw.println("</body></html>");
    pw.close();
    * putForm() writes an HTML form to the response
    public void putForm(HttpServletRequest req,
    PrintWriter pw)
    throws IOException
    pw.println("<form action=\"" +
    req.getRequestURI() +
    "\" method=post>");
    pw.println("<p><strong>Test Input: </strong>");
    pw.println("<input type=\"text\" " +
    "name=\"testinput\" value=\" \" size=12 maxlength=12>");
    pw.println("<p><input type=\"submit\" " +
    " value=\"Submit Entries\" ");
    pw.println("<p><input type=\"reset\" " +
    " value=\"Clear Entries\" ");
    pw.println("</form>");
    } // END OF SERVLET

  • Shell Script - .app's, not working

    Here's the context: I'm writing a shell script that takes an input of a file and does something with it and outputs a new file. Just think of the something as a blackbox. But I don't want to settle for this. No, so that I don't have to type a tedious command in shell, e.g. "./myprogramme.sh inputfilename", I want to create an application. That way I can, e.g. drag "inputfilename" onto "myprogramme.app", and the same thing will happen.
    Okay, so taking baby steps, I though I'd just make a helloworld.app. I did the following:
    1. made helloworld.sh to simply execute:
    echo "greetings planet earth!"
    2. placed helloworld in the directory "~"
    3. opened terminal in "~"
    4. ran the commands (in terminal)
    mkdir -p helloworld.app/contents/macos
    mv helloworld.sh helloworld.app/contents/macos/helloworld
    chmod +x helloworld.app/contents/macos/helloworld
    This is supposedly what one should do to create an app.
    Here's my problem: when I double-click the helloworld.app, a messagebox says, "You can't open the application "helloworld.app" because it is not supported on this architecture."
    _Question 1_: why?
    _Question 2_: how do i create an app that will successfully execute a given shell script?
    p.s. I realise that this may not be the best forum thread, but i can't find a coding/shell-script thread.

    This is supposedly what one should do to create an app.
    not at all! you can not just rename a shell script with a .app extension and expect to get an application. the easiest way to turn a shell script into an application is to use automator. no need to create a separate .sh file open automator and make a workflow consisting of a single "run shell script" action. put whatever you want the shell script to do inside. save it as an application and you are done.
    Here's my problem: when I double-click the helloworld.app, a messagebox says, "You can't open the application "helloworld.app" because it is not supported on this architecture."
    _Question 1_: why?
    _Question 2_: how do i create an app that will successfully execute a given shell script?
    p.s. I realise that this may not be the best forum thread, but i can't find a coding/shell-script thread.

  • 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

  • Passing params from SQL file to Shell Script and then from Shell to SQL Fil

    Afternoon guys,
    Have a fun question for all you gurus in shell scripting out there. I have a shell script that is calling 2
    different SQL programs. My objective is to pass a variable called request_number from one sql program
    to the shell script and then from the shell script back to another SQL program. I will explain why I
    need this to happen.
    Here is what the shell script looks like which calls sql programs student_load_a.sql and
    student_load_b.sql. Student_load_a.sql basically creates the control file (.ctl) which is needed for the
    SQL*Loader and then student_load_b.sql reads the table that was just loaded and does the main
    processing. My main objective here is to be passing the request_number which is being generated
    using an Oracle Sequence in student_load_a.sql and using this generated number in my main
    processing in student_load_b.sql to select records from the table based on request_number.
    Any ideas ?Any help or recommendations is welcome and appreciated.
    *1. Shell Script*
    # Accept system input parameters
    p_user_id=$1
    p_job_id=$2
    # Create control files for sqlload
    sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_a.sql $p_job_id
    exit_status=$?
    # Do sqlloads
    sdesqlldr.exe userid=$p_user_id control=student_load-$p_job_id.ctl \
                                                 log=student_load-$p_job_id.log \
                                                 bad=student_load-$p_job_id.bad
    exit_status=$?
    # Main processing
    # sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id $p_request_number
    sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id
    exit_status=$?
    exit 0*2. student_load_a.sql (Would like to pass back the Sequence Number back to shell script and then use in student_load_b.sql*
    -- Accept system input parameters
    define p_job_id = &1
    spool student_load-$p_job_id.ctl
    select
    'append into table TMP_STUDENT_LOAD
    FIELDS TERMINATED BY '','' optionally enclosed by ''"''
    trailing nullcols
    (request_number CONSTANT ' || '''' || request_number_seq.nextval || ''',
    student_id)'
    from   dual
    spool off;
    exit 0;
    {code}
    *3. student_load_b.sql (This is a big file so I am only adding code that is relevant for the SQL)*
    {code}
    declare
      v_request_number    number(6);
      v_student_id                  number(7);
      cursor cur_student_load is
        select  student_id
        from   TMP_STUDENT_LOAD
        where  request_number = v_request_number
        order by 1;
    begin
        v_user_id := '&1';
        v_job_id := &2;
        -- This is the variable I would like to be be passing from shell script to student_load_b.sql
        -- v_request_number = '&3';
         open  cur_student_load;
         fetch cur_student_load into v_student_id;
          exit when cur_student_load%notfound;
          .... more logic of if then else in here
         close cur_student_load;
    end;
    {code}
    Edited by: RDonASnowyDay on Jan 29, 2010 4:03 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    How come you are mixing WinDoze script (*.exe) with Unix?
    You are aware that you will be passing the password along with the user id to the second sql script?
    I will assume Unix ksh:
    # Accept system input parameters
    p_user_id=$1
    p_job_id=$2
    # Create control files for sqlload
    p_seqno=`sqlplus -s $p_user_id @$STUDENT_PATH/student_load_a.sql $p_job_id`
    exit_status=$?
    # Do sqlloads
    sqlldr userid=$p_user_id control=student_load-$p_job_id.ctl \
           log=student_load-$p_job_id.log \
           bad=student_load-$p_job_id.bad
    exit_status=$?
    # Main processing
    # sqlplus -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id $p_request_number
    sqlplus -s $p_user_id @$STUDENT_PATH/student_load_b.sql \
               $p_user_id $p_job_id $p_seqno
    exit_status=$?
    exit 0And the first sql script would look like this:
    -- student_load_a.sql
    -- Accept system input parameters
    set echo off pages 0 feed off lin 80 trims on ver off
    def p_job_id = &1
    col seqno NEW_VALUE seqno
    select request_number_seq.nextval seqno from dual;
    set term off
    spool student_load-$p_job_id.ctl
    select
    'append into table TMP_STUDENT_LOAD
    FIELDS TERMINATED BY '','' optionally enclosed by ''"''
    trailing nullcols
    (request_number CONSTANT ''&&seqno'',
    student_id)'
    from   dual
    spool off;
    exit 0;
    {code}
    :p                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Sql loader shell scripting

    Hi All,
    I need help on sql loader shell scripting basically since my input file is csv file will load into some target table say xx_90 along defining with control and data file. what where the data that goes into the bad file a segment of scripting that keep watching on badfile directory path if any bad file it finds it should move to a sperate database error table.
    Plz any sqlloader shellscripting experts can provide me the solution for this. Its a very urgent code i need to deliver I need the sample code for this your help is highy appreciated
    thanku
    sahana

    thanku..............when the load fails it moves to bad file script something like filewatcher it sees the data in the badfile and loads into the database error table........as i am basically businessobjects developer as for time being they have assinged me the task i did few manual loading on sql loader but i never have any experince on writing unix scripting i am quite worried to get this script done........
    can i use the samecode for the failed bad records into seperate external table......
    here i would change the path location and the rest goes as it isright............................i have the script for loading the datainto the targetsomething like this:
    sqlldr userid=ops$NGPTQMS/[email protected] \
    control=${evncpaq1/apps/cp/cm/r11.5.10/geae/gl/include/PAY0001_test.ctl} \
    data=${evncpaq1/data/infile/mon_gross_det.dat} \
    log=${evncpaq1/data/infile/mon_gross_det.log} \
    discard=${evncpaq1/data/infile/mon_gross_det.dis} \
    errors=999
    #bad=${BAD_FILE} \
    if [ $? -ne 0 ]; then
    echo "Error ! The sql loader call failed "
    exit 1
    fi
    IF any error is there in the script plz modify it and plz provide the complete code where to incorporate the code which you have written for bad file. Would be set it in seqence the steps so that i can run it in cron tab basically i have no other support for me to assist me on the job.......
    my dba has sent me the mail something like this:
    Please see the attached script to archive the source file once we are done with loading the data to the database. You already have the script for loading the data to the database. Please incorporate the attached script with your loading script. This script is generic and can be used to archive the bad file also once it has been loaded into the database (in case of any failures). This script send an email in case of any failures to the defined email distribution list. Right now the assumption is to run this through the cron. It we need to run this through the Appworx I will have to do some changes in the script. Also we will have to install the appworx agent on the server. Please let me if we need to need to run this through appworx I will create the appworx module for the same.
    and the archive script he sent is:
    . $HOME/.profile
    # Script to Archive SysLog files
    # This script accepts 2 parameters
    # - 1: Script Name          2: File Name
    # Created By : Pravin Darbare
    # Creation Date : 03/19/2008
    # Modified Date :
    # Modification History :
    echo "Starting SysLog_archiving Process"
    # Set Environmental Variables
    echo "Invoke Set Variable Script `date '+%H%M%S'`"
    # Set Local Script Variables
    #SCRIPT_NAME=$1
    SOURCE_DIR=$1
    FILE_NAME=$2
    # Zipping and Archive Source File
    echo "Zip Source file `date '+%H%M%S'`"
    #cp $LOAD_SRC_FILES/$SOURCE_DIR/$FILE_NAME $LOAD_SRC_FILES/syslog/Old_$FILE_NAME
    gzip /$SOURCE_DIR/$FILE_NAME
    check_rtn_status=$?
    if [ $check_rtn_status != 0 ]; then
    echo "Zipping source file Syslog process unsuccessfull"
    mailx -s "Zipping source file during Syslog unsuccessfull" $PR_PAGER_EMAIL_LIST </dev/null
    exit 1
    fi
    echo "Archive Source File `date '+%H%M%S'`"
    mv /$SOURCE_DIR/$FILE_NAME.gz /$SOURCE_DIR/archive/$FILE_NAME.gz$FILE_EXT
    check_rtn_status=$?
    if [ $check_rtn_status != 0 ]; then
    echo "Archiving source file during Syslog load process unsuccessfull"
    mailx -s "Archiving source file during Syslog load process unsuccessfull" $PR_PAGER_EMAIL_LIST </dev/null
    exit 1
    fi
    # example of calling file Syslog_archiving_Files.sh /apps/syslog/source_dir a.txt
    # example of calling file (Bad file) Syslog_archiving_Files.sh /apps/syslog/source_dir_bad a.txt
    # You need to have directory "archive" in both pathes .
    based on the complete detailed mail must having some view plz provide me something like exact code the rest path directories i will change it........
    for me its highly urgent to keep up my job
    Your support is highly appreciated
    Thanks&Regards
    sahana

  • Automator: running forever after executing a shell script?

    Hi,
    so i have found this little automator workflow that will start MAMP's Apache & MYSQL servers automatically (saved workflow as app then put into my login item autostart) however the script just keeps running forever and never exits (which should prompt a small Growl notification as feedback.
    The Script:
    <pre class="jive-pre" style="white-space:pre-wrap;width:585px;">
    on run {input, parameters}
    *do shell script* "/Applications/MAMP/Library/bin/apachectl start" password "my_password" user name "jannis" with administrator privileges
    *do shell script* "/Applications/MAMP/Library/bin/mysqld_safe --port=3306 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --lowercase_tablenames=0 --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysqlerrorlog &"
    *do shell script* "exit 0"
    return input
    end run
    </pre>
    This is what shows when it runs:
    Any ideas on what I am doing wrong for it to just keep spinning the little cog wheel and not exiting?
    PS: Both services are being started successfully! So the shell scripts seem to be run and doing their job just fine, just that they do not exit.
    Thanks for looking.
    Jannis

    This is a common question with do shell script. The issue is that mysqld_safe doesn't exit until MySQL shuts down, so your do shell script is hanging around waiting, essentially hanging your workflow.
    The solution is to redirect the stdout and stderr of the mysqld_safe command to a temp file. This releases the hooks that do shell script has on the command allowing the workflow to continue. To do this, just append '> /dev/null 2>&1' to the end of the shell command, like:
    do shell script "/Applications/MAMP/Library/bin/mysqld_safe --port=3306 --socket=/Applications/MAMP/tmp/mysql/mysql.sock --lowercase_tablenames=0 --pid-file=/Applications/MAMP/tmp/mysql/mysql.pid --log-error=/Applications/MAMP/logs/mysqlerrorlog >/dev/null 2>&1 &"
    As an aside:
    do shell script "exit 0"
    This line is worthless. I'm not sure what you're trying to achieve here

  • Having problems with a shell script

    I'm trying to write a shell script that will echo back the command, and ask for confirmation before proceeding with the command.
    Here is what I have so far:
    Josh:~ josh$ cat ~/Desktop/safe
    #!/bin/sh
    echo "You have typed: "$1 $2 $3 $4"."
    read -p "Are you sure you want to continue? (y/n)" a
    if [ "$a" = "y" ]; then
    $1 $2 $3 $4
    elif [ "a" = "n" ]; then
    exit
    elif [ "a" != "y" ] [ "a" != "n" ];then
    echo "Type y or n."
    fi
    When I run it, and type n, (y works fine) I get a syntax error: ./safe: line 10: [: too many arguments
    Could you please help me fix it?
    Thanks!
    EDIT: If I change the last "elif" statement to a simple "else", it automatically does that statement anyway when the user types "n".
    Is there any better way to end the script when the user types "n"?
    Message was edited by: joshz
    Message was edited by: joshz
    Message was edited by: joshz
    Message was edited by: joshz

    joshz wrote:
    A few q's.
    1. you have "n=$#", but never use n. What is that for?
    Er... because I originally did it differently and then forgot to go back and delete this line!
    2. Why do you set list to a blank string? Just to initialize it?
    Yes. Habit. Sometimes it is an error to use an unassigned variable. It would not matter in this case because echo will not complain, but it still appeals to my sense of logic/tidiness. It also means that if I later change something in my script so that an unassigned variable will cause an error, I won't be stymied by a failure I can't explain. (Not really an issue in a script this short but might well be in a longer script.)
    3. "sed 's+, $+ and all enclosed files/folders+'" What does it do? What is s supposed to do? I know that s treats a string as a single line, but what's the purpose of that (and the +)? $+ would stand for the end of a line, but repeated one or more times. Why have the +'s?
    In this case, s is for substitute. The + is an arbitrary delimeter. A forward slash is standard, but if I use + I don't have to escape the slash in the phrase "and... files/folders". The whole thing says:
    Take the piped output from echo and find every occurrence of the pattern consisting of a comma followed by a space followed by an end of line (on every line of the piped input, but there's only one here). Substitute the first occurrence you find (on every line of the piped input, but there's only one here) with a space followed by "and... files/folders".
    Also, I ideally want the "and all enclosed files/folders" to appear only if there is a recursive option turned on, not all the time. (I guess it would be good enough to have it turn on if there's an r OR R option, because it would be too hard to program it in based on each command).
    To do that properly, you need to do things differently so that you can distinguish between arguments to the command and occurrences of strings in the names of files and folders. For example, you might have a folder named "My Folder-Revised". There are ways of doing this but they are not as simple as the sort of framework you're using here.
    If you are concerned about accidentally deleting files, have you considered using an alias called "rm" for "rm -i". That way, you do not have to remember to use "safe" either. Unfortunately, that won't work for "sudo rm". On the other hand, "sudo safe" won't necessarily work either. Where are you planning to install your script?
    - cfr

Maybe you are looking for

  • BEA query is taking long time to run

    Hi All, I am using BEA Weblogic 10.2. I am performing seraching in the repository. The query string is: cm_lifeCycleStatus==4&&SERVICE == 'RBT' &&COPYRIGHTTO >= toDate('yyyy-MM-dd', '2010-07-01')&&COPYRIGHTFROM <= toDate('yyyy-MM-dd', '2010-07-01') H

  • How did old Safari History Items I haven't visited in years appear recently?

    I upgraded to Mountain Lion on Saturday October 13th. I then ran software updates, and got everything up to date. I was home alone, and the only thing I went to YouTube for was to get guidance for setting up Facebook and Twitter notifications. That's

  • How can I restore a deleted language to Ipad?

    I used icleaner (Cydia Tweak) to delete some un important data but it deleted Persian Language. So now I use the keyboard and It doesn't type any word I think the whole language has been deleted from my Ipad (3). How can I restore that language? plea

  • Need to view .DAT file in Windows 7

    I saw this question here before but it was unanswered., How do I load a DAT file on my Windows 7 Palm software? I desperately need my address book. Is there a program to convert it to the file type that this program wants to see? HELP! Post relates t

  • DO NOT DOWNLOAD YOSEMITE10.10.3 CRASHED ENTIRE DUAL DRIVE SYSTEM

    COMPUTER WILL NOT BOOT WILL NOT SHUT OFF CONSTANT REBOOT TRIED TO REPAIR USING DISK UTILITY IN "SAFE MODE" GETS TO PASSWORD PAGE I CAN ENTER IT IN BUT IT ALWAYS COMES UP AS 6 ...CPU CORE ERROR CATASTROPHIC FAILURE PLEASE PUSH ANY KEY TO REBOOT