Injecting into shell history with perl?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Injecting into shell history with perl?
# 1  
Old 05-25-2011
Injecting into shell history with perl?

How do I determine what my default shell is? If I'm root, how do I determine what my user's default shell is?

I think I'm running bash by default.

How do I write a perl program that can inject history into the shell's history so it can be retrieved with the history | grep command?

I have an old fashioned console (non-GUI) style perl program that asks dozens of questions. Incorporating readline might mitigate this a bit. What I would like to do is enhance the logic of this program to check ARGV before prompting the console (user) for information and then, after all the questions have been answered, artificially inject the completed command line into the shell history so the command can be re-run again with identical inputs by just hitting the up-arrow. This will save them from having to type all that stuff in again.

Can this be done?
Thanks!
Siegfried
# 2  
Old 05-25-2011
The type of shell you have is recorded in the "/etc/passwd" file.

To view your shell, you can issue:
Code:
egrep 'userid' /etc/passwd

Most systems have a global variable (SHELL) set, then you can issue:
Code:
echo $SHELL

As for being able to recall command history:
Code:
set -o vi

# 3  
Old 05-25-2011
Quote:
I have an old fashioned console (non-GUI) style perl program that asks dozens of questions. Incorporating readline might mitigate this a bit. What I would like to do is enhance the logic of this program to check ARGV before prompting the console (user) for information and then, after all the questions have been answered, artificially inject the completed command line into the shell history so the command can be re-run again with identical inputs by just hitting the up-arrow. This will save them from having to type all that stuff in again.
I don't think it's a good idea to hack the history to implement another hack in your program.

The ARGV stuff should be easy. Just check the length of ARGV array to see if you got enough command-line inputs. Also, you may want to validate the input data just as a good practice. Even if a user has supplied enough arguments, they could still be badly formatted. Also, be sure to display to the user what the inputs should be.

As for repeated executions of the same script with different inputs, you could easily modify the script to function in a loop, and provide some option for the used to update each value every time the loop runs. What I imagine is a prompt that will default to the previous values used for each parameter of the call, then ask for an updated value. If the user enters nothing, then it would just use the default. If the user enters some new value, it would use that new value.
# 4  
Old 05-26-2011
Long command lines

This program prompts for a lot of numeric IP addresses among other things. Composing a command line with a couple of dozen command line arguments could get a little tedious. Sure I can do syntax checking after the perl program starts, but then the user will have to abort (^C) and hit up arrow and fix the command line argument. Ugghhh...

The user could issue no command line arguments and let my perl prompt for everything and check the syntax of each of the responses and then I could write a script file with all these arguments should they want to do it again. But then the user has to run an editor to make changes and I was hoping to not have to burden the user with that.

Hmmm... I cannot think of any other options. I guess this is why XWindows was invented...

Thanks!
Siegfried
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting shell to Perl I run into shell built in function trap and need alternative in Perl

I am working on converting shell to Perl script. In shell we have built in function trap Do you know alternative in Perl or actually we don't need it? Thanks for contribution (3 Replies)
Discussion started by: digioleg54
3 Replies

2. UNIX for Dummies Questions & Answers

How to make each login shell history independent for same account?

Hello All, Many developers in our company use same application account to log in Linux Box for code development, how can i redirect my log in shell history to a different file to avoid history being shown to others or accidentally execute the same command which i or others executed? Thank you. (4 Replies)
Discussion started by: Ariean
4 Replies

3. UNIX for Dummies Questions & Answers

History to Another file [local user history , but root access]

Hi all, My need is : 1. To know who , when , which command used. 2. Local user should not delete this information. I mean , with an example , i can say i have a user user1 i need to give all the following permissions to user1, : a. A specific directory other than his home... (1 Reply)
Discussion started by: sriky86
1 Replies

4. UNIX for Advanced & Expert Users

History to Another file [local user history , but root access]

Hi all, My need is : 1. To know who , when , which command used. 2. Local user should not delete this information. I mean , with an example , i can say i have a user user1 i need to give all the following permissions to user1, : a. A specific directory other than his home... (3 Replies)
Discussion started by: linuxadmin
3 Replies

5. Programming

Unix shell with history features like in bash

hii to all i am developing a simple unix shell in c i want to add history feature in that how could i do that plz help if there is any tutorial or website plz put it here history feature should be like that in bash, when press up key show the previous command typed in console plz be... (1 Reply)
Discussion started by: vipin_jss
1 Replies

6. Shell Programming and Scripting

injecting new line in sed substitution (hold space)

Morning, people! I'd like to call upon your expertise again, this time for a sed endeavor. I've already searched around the forums, didn't find anything that helped yet. background: Solaris 9.x, it's a closed system and there are restrictions to what is portable to it. So let's assume I... (4 Replies)
Discussion started by: ProGrammar
4 Replies

7. HP-UX

shell history

When I try to run previous commands from the shell history, some irrelevent output is given (something like a script coding). What is the reason for this? (1 Reply)
Discussion started by: sube
1 Replies

8. UNIX for Dummies Questions & Answers

korn shell script to keep history of same file

Hello, How do I write a korn shell that will rename file with the current date. What I want to do is, I have a file that is re-written every day. But instead, I want to keep a 14 day history of the file. So I want to write a script that will rename the current file with a date attached to the... (2 Replies)
Discussion started by: watson2000
2 Replies
Login or Register to Ask a Question