sexta-feira, agosto 27, 2004
LX Debug de programas linux
outros exemplos:
strace PROGRAMA > LOG
strace PROGRAMA | tee LOG
LX Busca arquivo por nome e conteúdo
find . -print | fgrep -v '.o' | fgrep -v '.c' ou
find | fgrep -v '.o' | fgrep -v '.c'
Para procurar por uma expressão em todas os arquivos no diretório atual, apenas digite:
egrep -i "expressao de busca" *
Para procurar por strings em todas os arquivos dentro da árvore de diretórios, você pode combinar o find ou outros comandos da busca de nome de arquivos com, por exemplo, o egrep. Isto pode ser feito de diversas maneiras:
find . -type f -print | xargs egrep -i "expressao"
egrep -i "expressao" `find . -type f -print`
LX Mount do Samba
NC grant no Mysql
NC Recuperação de senha do Mysql para Windows
após isto sobrescrever somente os bancos de usuário
NC Servidor gratuito
NC Advanced Event Listeners
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SomeGUI extends JFrame
{
JButton run = new JButton("Run the Utility");
JButton exit = new JButton("Exit After Save");
JPanel buttons = new JPanel(new GridLayout(4,1,2,2));
protected void buildGUI()
{
buttons.add(run); buttons.add(exit);
this.getContentPane().add("Center",buttons);
exit.addActionListener(new ExitHandler());
}
// add inner class event handler for each button here
class ExitHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
public static void main(String[] args)
{
SomeGUI app = new SomeGUI();
app.setTitle("Layered GUI Demo");
app.setBounds(100,100,250,150);
app.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
app.buildGUI();
app.show();
}
}
Anonymous inner classes have no name (hence no name conflict) and are used
when only one instance of the class is required. They also do not have
constructors. Anonymous inner classes are most often found in event
listeners. A simple example for the exit button is:
exit.addActionListener(new ActionListener()
{
public void ActionPerformed(ActionEvent e)
{
System.exit(0);
}
});
As event classes are interfaces, all methods within that event must be
implemented.
Adapter classes provide default do-nothing methods which you can chose
to override.
Here is a short example using the WindowAdapter class to avoid coding
all seven window events.
import java.awt.*;
import java.awt.event.*;
class Listener2 extends Frame
{
Listener2()
{
addWindowListener(new WindowAdapter()
{
public void windowclosing (WindowEvent e)
{ System.exit(0); }
});
setSize (200,200);
setVisible(true);
}
public static void main (String [] args)
{
new Listener2();
}
}
NC Basic Event Listeners
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Frame3 extends JFrame implements ActionListener
{
JPanel panel = new JPanel(); // create panel object
JLabel prompt = new JLabel(" Enter a number: ");
JTextField answer = new JTextField ("", 5); // constrain length
JButton pressme = new JButton("Press Me");
// first comes the constructor
Frame3()
{
Container con = this.getContentPane(); // inherit main frame
con.add(panel);
pressme.setMnemonic('P'); // associate hotkey
pressme.addActionListener(this); // register button
panel.add(prompt);
panel.add(answer);
panel.add(pressme);
answer.requestFocus();
}
// now the event handler
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if (source == pressme)
{
JOptionPane.showMessageDialog(null,"I hear you!","Message Dialog",
JOptionPane.PLAIN_MESSAGE); // show something
}
}
// and finally the main method
public static void main(String[] Args)
{
Frame3 app = new Frame3();
app.setTitle("Event Handler Demo");
app.setBounds(100,100,300,200); // position frame
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
app.setVisible(true);
}
}
NC static Java (continuação)
import java.util.ResourceBundle;
class Errors {
static ResourceBundle errorStrings;
static {
try {
errorStrings = ResourceBundler.getBundle("ErrorStrings");
} catch (java.util.MissingResourceException e) {
//error recovery code here
}
}
}
NC static Java
class AnIntegerNamedX {
static int x;
static public int x() {
return x;
}
static public void setX(int newX) {
x = newX;
}
}
NC Interfaces Java
Interfaces are similar to abstract classes but all methods are abstract and all properties are static final.
When a class implements an interface, the class agrees to implement all the methods defined in the interface.
You use an interface to define a protocol of behavior that can be implemented by any class anywhere in the class hierarchy. Interfaces are useful for the following:
* Capturing similarities among unrelated classes without artificially forcing a class relationship.
* Declaring methods that one or more classes are expected to implement.
* Revealing an object's programming interface without revealing its class.
If an object wants to be notified of mouse clicks, the Java platform event system requires that the object implement the MouseListener interface.
The Implements statement is used as part of a technique that separates the interface of an object from its implementation, so that multiple implementations of the interface can be developed.
Just as classes extend other classes, interfaces can extend other interfaces (but not classes).
NC Tutorial Java
LX Mais Comandos
lastlog - Mostra o último login dos usuários cadastrados no sistema.
LX Comandos
find -type [f,d,l] (somente arquivo diretório ou link)
grep -r TEXTO ARQUIVO
date MMDDHHmm
uname -a
dpkg -i PACOTE (debian)
installpkg (slackware)
history
LX Procura Texto no Arquivo
LX Guia Foca Manual
e Dicas L (Unicamp)
http://www.dicas-l.unicamp.br/
e OpenOffice Brasil
http://www.openoffice.org.br
LX Processo no Linux
free -s tempo (memória utlizada)
vmstat (memória virtual)
bg pid (background)
fg pid (foreground)
LX Árvore de processos
LX Dois Terminais X
startx -- :0 (display)
startx -- :1
se quiser chamar apenas o xterm
xinit -- :0
xinit -- :1
LX Starting many X sessions
LX Running X11 Applications Remotely
The easiest way to run X11 applications at home, and the method we recommend, is to use SSH forwarding to forward X11 applications to your local X server. To do this, you will need two applications -- an X server, and an SSH terminal application.
X11 Servers
Windows
X-Win32 - Most commonly used X server for windows, fairly priced with an educational discount.
Exceed - Another popular X server, stable, full featured, and equipped with many extra tools.
Cygwin/XFree86 - Free, though the Windows port of XFree86 is still very much in development, and does not run properly on many configurations. Also required is a decent understanding of UNIX and setting up XFree86. Still, for free you can always give it a try.
Linux/*BSD
XFree86 - Probably came with your distribution. XFree86 is the most common implementation of X found on Linux and the various BSD distributions. It is fast, stable, and free.
Mac OSX
X11 for Mac OS X is available from apple for versions of OSX earlier than 10.3
For OS X version 3 (panther) and up X11 is included on the os cds
Mac OS Classic
eXodus - Same as above, however the SSH tool does not function.
SSH Software
Linux, Mac OSX, and other *NIX variations typically come with variations of SSH. If not, you may need to install a version such as OpenSSH.
See our Shell/SSH Access page for more information on SSH clients for other operating systems.
Setting up X11 Forwarding
Many, but not all SSH clients currently available support X11 Forwarding, and general port forwarding. This allows network traffic to be forwarded from the remote machine to your local box through SSH. The result is that with very little configuration, this traffic is forwarded to you machine, encrypted in an SSH "tunnel".
There are several reasons this is a preferred method to run X11 applications remotely:
Most importantly, the transmission is secure. Any data, passwords, etc. is encrypted within the SSH tunnel.
Setup is easy. In most situations, all you need to do is have your X server running. There is no need to modify permissions for foreign hosts, and no need to set your DISPLAY variable. SSH does it all for you.
With SSH compression turned on, it can actually be faster to use SSH than not on low bandwidth connections.
To set up SSH port forwarding, you simply need to enable that option in your client. We outline a few examples below for common clients:
NOTE: We recommend against using any SSH program that does not support SSH version 2. We will be switching to version 2 exclusively in the future due to security flaws in version 1. Recent versions of PuTTY, MacSSH, and OpenSSH support both SSH2 and port forwarding.
PuTTY
Set up a new session or load an existing one, and set all the appropriate settings you desire.
Go to Connection -> SSH -> Tunnels.
Make sure the checkbox "Enable X11 Forwarding" is checked. The box below it should read "localhost:0". If you are forwarding to your local machine (most likely) this is fine.
Return to Session, the opening settings window.
Type in the name of your session, and click "Save".
MacSSH
Go to the menu item Favorites -> Edit Favorites.
Either create a "New" entry, or select an existing one and click "Edit".
Enter the hostname and any other desired information.
Go to the "SSH2" tab.
Make sure the checkbox "Forward X11" is checked.
Save your favorite by clicking "OK".
OpenSSH or the commercial SSH Client
X11 forwarding is typically turned on by default in most *NIX distributions of SSH. If it is not, you can enable it by calling SSH with the "-X" option. For example:
% ssh -X username@unix.ece.pdx.edu
You can also change this option in the SSH configuration files. Please refer to the SSH documentation for more.
Running your Application
This is the best part! First, start your X Server if it isn't running already. To run the X application you want, simply SSH in to the machine you desire, and run the program. The program should display on your screen, probably after some delay as it loads.
Speed
Note that X11 requires a lot of network traffic. You can not realistically run large, graphics intensive applications over a 56K modem. Netscape, for example, can take up to 10 minutes simply to start and display your home page. No exaggeration. But some applications are fairly reasonable, especially on a broadband connection such as DSL or Cable. Feel free to experiment with various settings. Many X servers support options that will speed up performance over low bandwidth connections such as caching data, or not refreshing windows that aren't in focus. Turning on compression in your SSH client can also help in some situations.
Fonts
You may run into some applications that require additional fonts to run properly. The Mentor Tools are a common example. Even though it is possible to get dmgr to run with font substitution, it's not very useful when you can't tell what button goes where.
StarNet, the makers of X-Win32, provide some extra fonts for tools including Mentor on their site:
http://www.starnet.com/support/extrafonts.htm
These fonts are intended for X-Win32, but many have used them with other OSes and X servers as well. If you run into problems, you may need to search the web for other options. If you find something useful, feel free to e-mail us at support@cat.pdx.edu, and we will be glad to add it here.
Link
LX Perguntas e Respostas XFree86
LX sites
LX XFree86
xlogo
X11perf
LX Site LinuxJournal
LX Xinerama
The beauty of the Xinerama extensions is that they are totally transparent to user space. Previously, applications could only reside on one of the displays and could not be moved between the two. Window managers had to be specially written to support the two displays. With Xinerama, window managers and applications don't have to be specially written to support the larger "Virtual Desktop" which Xinerama creates.
Link
LX Documentação XFree86
LX /proc/net explicado
/proc/net/
This directory provides a comprehensive look at various networking parameters and statistics. Each of the files covers a specific range of information related to networking on the system. Below is a partial listing of these virtual files:
arp — Contains the kernel's ARP table. This file is particularly useful for connecting a hardware address to an IP address on a system.
atm — A directory containing files with various Asynchronous Transfer Mode (ATM) settings and statistics. This directory is primarily used with ATM networking and ADSL cards.
dev — Lists the various network devices configured on the system, complete with transmit and receive statistics. This file lists the number of bytes each interface has sent and received, the number of packets inbound and outbound, the number of errors seen, the number of packets dropped, and more.
dev_mcast — Displays the various Layer2 multicast groups each device is listening to.
igmp — Lists the IP multicast addresses which this system joined.
ip_fwchains — If ipchains are in use, this virtual file reveals any current rule.
ip_fwnames — If ipchains are in use, this virtual file lists all firewall chain names.
ip_masquerade — Provides a table of masquerading information under ipchains.
ip_mr_cache — Lists the multicast routing cache.
ip_mr_vif — Lists multicast virtual interfaces.
netstat — Contains a broad yet detailed collection of networking statistics, including TCP timeouts, SYN cookies sent and received, and much more.
psched — Lists global packet scheduler parameters.
raw — Lists raw device statistics.
route — Displays the kernel's routing table.
rt_cache — Contains the current routing cache.
snmp — List of Simple Network Management Protocol (SNMP) data for various networking protocols in use.
sockstat — Provides socket statistics.
tcp — Contains detailed TCP socket information.
tr_rif — Lists the token ring RIF routing table.
udp — Contains detailed UDP socket information.
unix — Lists UNIX domain sockets currently in use.
wireless — Lists wireless interface data.
LX Proc detalhado
cmdline — Contains the command issued when starting the process.
cpu — Provides specific information about the utilization of each of the system's CPUs. A process running on a dual CPU system produces output similar to this:
cpu 11 3
cpu0 0 0
cpu1 11 3cwd — A symbolic link to the current working directory for the process.
environ — Gives a list of the environment variables for the process. The environment variable is given in all upper-case characters, and the value is in lower-case characters.
exe — A symbolic link to the executable of this process.
fd — A directory containing all of the file descriptors for a particular process. These are given in numbered links:
total 0
lrwx------ 1 root root 64 May 8 11:31 0 -> /dev/null
lrwx------ 1 root root 64 May 8 11:31 1 -> /dev/null
lrwx------ 1 root root 64 May 8 11:31 2 -> /dev/null
lrwx------ 1 root root 64 May 8 11:31 3 -> /dev/ptmx
lrwx------ 1 root root 64 May 8 11:31 4 -> socket:[7774817]
lrwx------ 1 root root 64 May 8 11:31 5 -> /dev/ptmx
lrwx------ 1 root root 64 May 8 11:31 6 -> socket:[7774829]
lrwx------ 1 root root 64 May 8 11:31 7 -> /dev/ptmxmaps — Contains memory maps to the various executables and library files associated with this process. This file can be rather long, depending upon the complexity of the process, but sample output from the sshd process begins like this:
08048000-08086000 r-xp 00000000 03:03 391479 /usr/sbin/sshd
08086000-08088000 rw-p 0003e000 03:03 391479 /usr/sbin/sshd
08088000-08095000 rwxp 00000000 00:00 0
40000000-40013000 r-xp 00000000 03:03 293205 /lib/ld-2.2.5.so
40013000-40014000 rw-p 00013000 03:03 293205 /lib/ld-2.2.5.so
40031000-40038000 r-xp 00000000 03:03 293282 /lib/libpam.so.0.75
40038000-40039000 rw-p 00006000 03:03 293282 /lib/libpam.so.0.75
40039000-4003a000 rw-p 00000000 00:00 0
4003a000-4003c000 r-xp 00000000 03:03 293218 /lib/libdl-2.2.5.so
4003c000-4003d000 rw-p 00001000 03:03 293218 /lib/libdl-2.2.5.somem — The memory held by the process. This file cannot be read by the user.
root — A link to the root directory of the process.
stat — The status of the process.
statm — The status of the memory in use by the process. Below is a sample /proc/statm file:
263 210 210 5 0 205 0
The seven columns relate to different memory statistics for the process. From left to right, they report the following aspects of the memory used:
Total program size, in kilobytes
Size of memory portions, in kilobytes
Number of pages that are shared
Number of pages that are code
Number of pages of data/stack
Number of library pages
Number of dirty pages
status — The status of the process in a more readable form than stat or statm. Sample output for sshd looks similar to this:
Name: sshd
State: S (sleeping)
Tgid: 797
Pid: 797
PPid: 1
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 32
Groups:
VmSize: 3072 kB
VmLck: 0 kB
VmRSS: 840 kB
VmData: 104 kB
VmStk: 12 kB
VmExe: 300 kB
VmLib: 2528 kB
SigPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 8000000000001000
SigCgt: 0000000000014005
CapInh: 0000000000000000
CapPrm: 00000000fffffeff
CapEff: 00000000fffffeffThe information in this output includes the process name and ID, the state (such as S (sleeping) or R (running)), user/group ID running the process, and detailed data regarding memory usage.
link de informações :
http://www.redhat.com/docs/manuals/linux/RHL-9-Manual/ref-guide/s1-proc-directories.html
LX visualizar processos (serviços) de quaisquer programas
um diretório que contém seus respectivos arquivos
um bom exemplo é pegar o do servidor X
ps ax |grep X
ir no /proc no seu pid e visualizar o consumo de memória
less status
LX visualizar todos dispositivos
LX informações processador
LX OpenOffice
formatar célula e código do formato
[>=7]"aprovado";[RED]"reprovado"
LX ls de diretórios
find -type d (é uma outra solução)
LX descompactar TAR.GZ
LX instalar RPM
LX dd
LX autofs
para configurar temos o arquivo /etc/auto.master e /etc/auto.misc
auto.misc
ponto de montagem tipo de fs e permissões device
cd -fstype=iso9660,ro,sync,nodev,nosuid :/dev/cdrom
auto.master
raiz de montagem arquivo de configuração tempo de desconecção
/mnt /etc/auto.misc --timeout 1
startar o serviço
/etc/init.d/autofs start
NC Nat modem SpeedTouch
bind
application ftp (exemplo no caso ftp)
port ftp (exemplo ftp)
save