Mal James

Greenhorn
+ Follow
since Aug 08, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mal James

Hi Again, just to close off this topic.
The send/expect solution worked but was not a success due to vast amounts of "control" characters suddenly appearing in the output (^M being the most prevalent) and totally messing up all previous formatting and mailings from the jobs that were run through this mechanism. This comes from Tcl apparently.

Eventually we allowed our "batch" userid to sudo "nopasswd" to the instance userids but only to use specific DB2 libraries and java.
5 years ago
Thanks again to all who contributed - it is much appreciated.
The answer - or at least, an answer for now - seems to be to install send/expect on the Unix box. Then I can create a send/expect script on the fly in Java and call it with the decrypted password as the parm. Irritatingly specific to Unix boxes with send/expect installed so not a complete answer. Hopefully I will find time soon to browse the send/expect source code in Tcl and see if there is a way in Java to do the same as it does. Send/expect manages to push the password into sus' input stream so there must be a way.
5 years ago
Thanks Campbell - haven't actually tried to su in Linux yet. My initial need for that particular command is in AIX. But the CmdProc object has been running in Linux, Unix and Windows for a couple of years. Incidentally, I also had trouble following your link - something about ducks ??. But by chopping out the %2f inserts I found the sudo command. But I really want to set a session to the authority of a new user, not just run a single command.

Some background. Db2 task scheduler used to let us schedule batch jobs remotely under any userid through its' DAS protocol. But recently we moved to V10.5 and now have to use a userid that can SSH in to schedule the job. But some tasks (Eg. checking and pruning the diagnostic log and deleting old archive logs) require us to use the instance userid because Db2 creates the log file under that user with 600 permissions. So I need to submit the job under the SSH-enabled user but authorise several steps each of several lines with the instance userid. The Unix Admins don't want to grant the instance userids SSH because then the DBAs could use those ids directly (without having to use their own ids first) and no-one could tell who did what under the instance ids.

So thanks for your suggestion too Tim, but su -c also only runs a single command, rather than setting the session auth. This link says that su particularly gets its' password input from the terminal (/dev/tty) directly and I read somewhere that this is to avoid people being able to save their passwords in plain text and call su with redirected input.
I did spend some time thinking that su merely opens new stdIn and out streams and was looking for something like the ksh -i (or Windows cmd -i) which tells the shell to inherit current std streams. I used those in my cmdProc object. "su -i - userid" would have been nice......but there isn't one .

However, you appear to have cracked my problem!! If you scripted the code that you presented, how did you get the password input to su? 'cos that is all I am really trying to do; feed su a password from the java program controlling the shell. In java I can get the password from an encrypted file. And even with the -c option su still requires a password.
5 years ago
Thanks Tony. Makes sense. I didn't look deep enough to find the Linux/Unix forum.
5 years ago
Hi Gang, Hope this is on-topic for the forum. About I/O specifically on Linux/Unix cmd line.

Some background:
A couple of years ago I wrote myself an object called CmdProc which runs any valid operating system command and tells me when it has finished, returning the relevant command output/results on demand. It uses Stdin, Stdout and Error and works quite nicely on Linux, AIX and Windows. So that is up-and-running and I have a reasonable understanding of how to access the three standard streams. With most OS commands I can retrieve the commands' prompts and respond (in Java) with further inputs. All working Ok.

Now I am trying to use this mechanism to run the "su" command on Unix.
My problem is that (from some obscure documentation that I have found) su reads its' input from the current terminal NOT from Stdin. So I need to modify my code to present text as if it had come from the current tty instead of from Stdin.

Anyone got any ideas as to how I do that? Or can supply a link to give some direction.

I have searched the forum for "terminal" but it seems to be generically used for stdin Etc. so I didn't find anything that looked hopeful.
I have tried some "ignorant fiddling" with the TERM environment variable and have discovered that when the command line session is launched from Runtime.exec I appear to get something called a pts rather than a tty (not too sure what the difference is but it seems to be related to terminal type). I have found something called /dev/tty which can be written to through a "real" command line session but doesn't exist when I try it through a session created via Runtime.exec.

Bit stuck now so TIA,
Mal
5 years ago
Thank you Ulf, I will have a look at the httpClient.
Thank you, sorry for abusing the boffins' forum.

Could you pass some clues on how I pass a second request that looks (to the server) as if it came from the javascript that the server just sent me?
Hi All,
I am trying to write a Java standalone app (not an applet) that reads a webpage across the net and then responds to it (with a user and password on the first page).
I have got as far as creating an HttpsURLConnection, connecting to it, reading from it and printing the resulting page source which includes a <SCRIPT> tag. Now I want to send something ( a page? a PUT? Run a javascript that sends stuff? I don't know what ) back to the server.

As far as I can see, when the page is displayed in a browser, the script sends the user and password values from the screen back to the server. I have the user and password values available in the app but don't know what to do with them.

I have spent the morning trying to get direction for the next move ( Eg. I found Rhino and jQuery but they seem server-oriented and overkill ). Maybe I just need a subset???

Can anyone point me in the right direction as to how I buld up and send a response? That is, I know how to getOutputStream() and write to it but I don't know what to write.
Should I be trying to run the javascript script from Java (if so how?) or just doing some kind of 'POST' back to the server (if so what format?)?

Sorry for asking about what has clearly been done a million times before but I am going in Googlic circles at the moment.
All constructive comments gratefully received.
Wow! great, Thanks to all who responded - especially Steve. And I thought I liked Netbeans
I got bubbles
And I will definitely use the code tags next time.
BMPs are supported from 1.5 - I read a lot trying to make this go; Should've just asked sooner.
Thanks again,
Mal
11 years ago
Hi All,
I am a long term on-and-off programmer but new to java graphics. I have been beating my head for a week now but I still get no image on my little grey box.
No bubbles
I know that whatever I am doing wrong is really simple but I cannot see it. Could someone please show me my error. I have stripped out everything to just leave a basic box.
the code as given produces the error on my machine.
The initComponents () was generated by netbeans 6 in the original project and I am using Java 6. All it is supposed to do is draw the BMP as an image in the box. Easy I thought......
Thanks in advance,

Mal


import java.awt.image.* ;
import java.awt.* ;
import javax.swing.* ;

//These two only for test.
import java.io.* ;
import javax.imageio.* ;

public class TestBmp2 extends javax.swing.JFrame {

bmpPanel bp ;

public TestBmp2 ( String in_fname ) {
initComponents();
bp = new bmpPanel (in_fname ) ;
getContentPane () . add ( bp ) ;
setVisible ( true ) ;
}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jPanel1 = new javax.swing.JPanel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 329, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 259, Short.MAX_VALUE)
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(61, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(30, Short.MAX_VALUE))
);

pack();
}// </editor-fold>


public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TestBmp2 ("C:\\temp\\fedvalTest\\Soap Bubbles.bmp") ;
}
});
}

// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
// End of variables declaration


private class bmpPanel extends JPanel {

BufferedImage bi ;

public bmpPanel ( String in_fname ) {
try {

bi = ImageIO.read( new File ( in_fname ) );
if ( bi == null ) {
System.out.println ( "Image read null.") ;
} else {
}
} catch (IOException e) {
System.out.println ( "Image read error.") ;
}
}

public void paintComponent ( Graphics in_g ) {
super . paintComponent ( in_g ) ;
Graphics2D g = (Graphics2D) in_g ;
g.drawImage(bi, 100, 100, this);
}
} // End of inner class bmpPanel
}
11 years ago