Expect Terminal Macros

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect Terminal Macros
# 1  
Old 02-25-2008
Expect Terminal Macros

Hey people!

I just started out working at an ISP as tech support and thought that I should ease the work load by scripting some small macros.

I create different commands with Alias through .bashrc which are all directed to the same script file. Here I planned on using Expect to run different input macros. Problem i came across though is that I can't set a varible to the command i ran to execute the script file.

So i .bashrc i have written
alias command2="~/scirpt.file"

and in script.file i have made the different rules for each command.

An easy solution to the problem would be to create one script file for each command, but that isn't as neat, easpesially not if I want to distribute the script to my collegues.

What i need in script.file is a line that sets a variable to the command that I have inputed so i can create an if-statement for which action that should be taken.

so if i have the terminal like this.

ghettofish@server:~$ command2

then i should go to script.file and have a statement that does the following.

set input_command [code to retrive command that executed the script.file]

Then later i could create an if-statement that would be something like
if ($input_command == "command2") blah blah

Anyone got any ideas?
Hope someone could help me out with this.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Macros how-to?

Hi, all I just came to new system with RH, and it has alot of macros I was told to use, but I can't find how to open it for display or for edit, can you help me please, is it all about make/makefile? let say I have macro <trx> like this, that does a lot of things: >$ trx ... creating new... (1 Reply)
Discussion started by: trento17
1 Replies

2. Programming

help with atoi and macros in C

I have a PORT_NUM macro (10 digits long number) in a server file, if i do htons(PORT_NUM) i get warning: this decimal constant is unsigned only in ISO C90 warning: large integer implicitly truncated to unsigned type whats wrong with this? (2 Replies)
Discussion started by: omega666
2 Replies

3. Shell Programming and Scripting

How can I scroll the terminal output with Expect

Hi, I'm trying to come up with a simple expect script that allows me to login to a system and run a single command ... something like this: #!/usr/bin/expect -f # let's set some variables #set password set ipaddr set ponumber set hostname set timeout -1 # let's now connect to the... (0 Replies)
Discussion started by: danielsf
0 Replies

4. UNIX for Advanced & Expert Users

Using Macros in sftp command

Hi, I've some existing scripts wherein am using ftp + .netrc. I've defined my macros in .netrc file. I want to switch to sftp now but it seems it doesn't support macros and .netrc and it gives "command invalid" error. Is there any other alternative? Note: I don't want help for... (1 Reply)
Discussion started by: ps51517
1 Replies

5. Linux

What are the meaning of these macros..

Masters, I am trying to learn the serial mouse driver for linux kernel. On the kernel source tree I find out these macros and I am unable to find out the meaning of these macros. Please anyone help me to understand these. These macros are defined in linux/serio.h... (2 Replies)
Discussion started by: iamjayanth
2 Replies

6. UNIX for Dummies Questions & Answers

MAKE and its macros and variables

I want to build a Makefile that simply takes a template file and modifies it (sed or perl, probably) before installing the result in the right place - my problem is creating the variable for substitution... So I have SYSTEM = SYS1 SYS2 SYS1_CHANNELS = CHANNEL1 CHANNEL2 CHANNEL4... (1 Reply)
Discussion started by: JerryHone
1 Replies

7. Programming

One last question about capability macros

This might be poorly worded. In the header file, I have #ifdef LOCK_FCNTL #ifdef HAVE_FCNTL_H #include <fcntl.h> #endif #define LOCK(file) setlock(fileno(file), F_WRLCK); #define UNLOCK(file) setlock(fileno(file), F_UNLCK); #endif /* LOCK_FCNTL */ #ifdef LOCK_FLOCK #ifdef... (1 Reply)
Discussion started by: frequency8
1 Replies

8. Programming

How do capability macros get named?

The following is taken from some production code: #ifdef LOCK_LOCKF #ifdef HAVE_SYS_FILE_H #include <sys/lockf.h> #endif #ifdef HAVE_SYS_FILE_H #include <sys/file.h> #endif #define LOCK(file) fseek(file, 0L, 0), lockf(file, 1, 0L) #define UNLOCK(file) fseek(file, 0L, 0),... (2 Replies)
Discussion started by: frequency8
2 Replies

9. UNIX for Dummies Questions & Answers

saving macros for VIM

The question is , as the topic says, how does one save macros for VIM in the .vimrc. I had a look on web and it gave all this ****** about how to build turing machines in vim code or something but i just want to store a macro to like : if(){ } I know how to do it IN vim but .vimrc??????!?!?!... (3 Replies)
Discussion started by: yngwie
3 Replies

10. UNIX for Dummies Questions & Answers

troff macros

Hi, I'm going write a small handbook. The typesetting software I'm going to use is troff. There are -ms -me -mm macros for troff. Which one is the most suitable? Thanks! -Tony (2 Replies)
Discussion started by: tonyt
2 Replies
Login or Register to Ask a Question
DISLOCATE(1)                                                  General Commands Manual                                                 DISLOCATE(1)

Dislocate - disconnect and reconnect processes SYNOPSIS
dislocate [ program args... ] INTRODUCTION
Dislocate allows processes to be disconnected and reconnected to the terminal. Possible uses: o You can disconnect a process from a terminal at work and reconnect from home, to continue working. o After having your line be dropped due to noise, you can get back to your process without having to restart it from scratch. o If you have a problem that you would like to show someone, you can set up the scenario at your own terminal, disconnect, walk down the hall, and reconnect on another terminal. o If you are in the middle of a great game (or whatever) that does not allow you to save, and someone else kicks you off the ter- minal, you can disconnect, and reconnect later. USAGE
When run with no arguments, Dislocate tells you about your disconnected processes and lets you reconnect to one. Otherwise, Dislocate runs the named program along with any arguments. By default, ^] is an escape that lets you talk to Dislocate itself. At that point, you can disconnect (by pressing ^D) or suspend Dislo- cate (by pressing ^Z). Any Tcl or Expect command is also acceptable at this point. For example, to insert the contents of a the file /etc/motd as if you had typed it, say: send -i $out [exec cat /etc/motd] To send the numbers 1 to 100 in response to the prompt "next #", say: for {set i 0} {$i<100} {incr i} { expect -i $in "next #" send -i $out "$i " } Scripts can also be prepared and sourced in so that you don't have to type them on the spot. Dislocate is actually just a simple Expect script. Feel free to make it do what you want it to do or just use Expect directly, without going through Dislocate. Dislocate understands a few special arguments. These should appear before any program name. Each should be sep- arated by whitespace. If the arguments themselves takes arguments, these should also be separated by whitespace. The -escape flag sets the escape to whatever follows. The default escape is ^]. CAVEATS
This program was written by the author as an exercise to show that communicating with disconnected processes is easy. There are many fea- tures that could be added, but that is not the intent of this program. SEE ALSO
Tcl(3), libexpect(3) "Exploring Expect: A Tcl-Based Toolkit for Automating Interactive Programs" by Don Libes, O'Reilly and Associates, January 1995. AUTHOR
Don Libes, National Institute of Standards and Technology 7 October 1993 DISLOCATE(1)