output
stringlengths 9
26.3k
| input
stringlengths 26
29.8k
| instruction
stringlengths 14
159
|
---|---|---|
Yup. Previous runlevel, which in this case appears to be Singleuser mode.
|
who -r
run-level 4 2015-01-19 21:56 last=SI'm on slackware,what does it mean S?
Previous runlevel?
|
Who command: what is S on slackware?
|
This seems like what you're looking for. The issue as I see it is that there's always going to be at least 1 user that's logged in, i.e. the one accessing the menu, so you're looking for when the number of user's is 1.
$ who | awk '{print $1}' | sort -u | wc -l
1This takes the output of who and cuts just the first column off, i.e. the usernames, and then sorts it uniquely, and then counts it.
But IMO, it's a bit more complicated than that. Looking at the situation in this manner is ignoring if this user has any logged in SSH sessions, for example. So you probably want to check to see if the above output from who specifies that it's only :0 devices or if there are any pts/# types of lines.
Examples
# represents the login for the user's desktop on display :0
saml :0 2014-12-01 01:56 (:0)# represents user's terminals or SSH connections
saml pts/0 2014-12-01 01:57 (:0)NOTE: Notice how the pts/0 line shows which display it's associated with, ":0".
So something like this seems more appropriate:
num_pts=$(who | grep 'pts/' | wc -l)
num_usr=$(who | awk '{print $1}' | sort -u | wc -l)if [ $num_pts -eq 0 ] && [ $num_usr -eq 1 ]; then echo "OK to logout";fiExample
Here's a simulated run where I have 2 accounts logged in:
$ who
saml :0 2014-12-01 01:56 (:0)
saml pts/0 2014-12-01 01:57 (:0)
saml pts/1 2014-12-01 02:13 (:0)
saml pts/2 2014-12-03 04:22 (:0)
saml pts/3 2014-12-05 08:14 (:0)
samtest pts/4 2014-12-05 08:14 (localhost)Running the commands manually produces this:
$ echo $num_usr
2
$ echo $num_pts
5
$ if [ $num_pts -eq 0 ] && [ $num_usr -eq 1 ]; then echo "OK to logout";fi
$If I manually set the 2 variables, however, to simulate that I'm logged into ":0" and have no terminals open:
$ num_usr=1
$ num_pts=0
$ if [ $num_pts -eq 0 ] && [ $num_usr -eq 1 ]; then echo "OK to logout";fi
OK to logoutThis can be condensed and is just to show you an approach.
|
I'm working on a user menu so that when a user logs in all they get is this menu; on this menu is a selection of reboot option. I want one of the options to be reboot the system if no one is logged in.
I want a search to be carried out to see if anyone has logged in. I think this would be a good start:
# who | wc if the answer were 0 users I'd want the system to reboot. NOTE: I know it won't be because the user is logged in using the menu.
How can I find out if there's no other user logged in besides the one accessing the menu?
|
I want to reboot the system once a search had been done to see that no-one is logged in
|
As meuh says, the use of a pseudo-terminal may be forced with the -t option, and then the login will show-up with who. However whilst this a home system, if it weren't it still would concern me a little that if someone logged in without using that switch I might be unaware of his presence on my system without looking further into sshd's reporting options!
|
I'd like to perform selective shutdown of a server in my house after backing-up over SSH. My post-backup script waits for five minutes and then runs a very short 'safe shutdown' script located on the server. This script was using who -q to get the number of users logged on, however as I started executing this script non-interactively, i.e. using ssh user@server /home/common/bin/SafeShutdown.sh (well actually using PuTTY's plink right now but should make no difference), the user count being found was 0 if no interactive users were present. How can I either get who/w to work with non-interactive logins, or else use another method as an unpriveliged user to count how many people are logged on in any way, shape or form?
Thanks
|
How to Use who/w with Non-Interactive SSH logins
|
The who program is part of the coreutils package. You can use apk add coreutils to install it:
# which who
## apk add coreutils
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(1/3) Installing libacl (2.2.53-r0)
(2/3) Installing libattr (2.4.48-r0)
(3/3) Installing coreutils (8.31-r0)
Executing busybox-1.31.1-r8.trigger
OK: 7 MiB in 17 packages
## which who
/usr/bin/who
#
|
How to view all currently logged in users on Alpine Linux? It doesn't have who by default apk add who doesn't find any packages. Is there another package for Alpine that contains who? Or does it use some other utility for the same purpose?
I tried to look at the docs but searches for "list users" and "logged in users" didn't seem to yield results
|
How to view all currently logged in users on Alpine Linux?
|
users counts login sessions. From sudo: The su command is used to become another user during a login
session.(Emphasis is mine.) A login session creates a new tty, where as su uses the existing tty.
I just looked at the source code to the users command. What it does is read utmp. So I guess the bottom line is that if you write a program and write to utmp, you'll be seen in users.
|
How does users define what users are logged in?
If I ssh into a box twice, I see my username twice listed if I execute users. However, if I create a new login shell via sudo su -, I do not see root listed as users. Same goes for any other user such as sudo su - user. Of course, a non-login shell also doesn't show up in users.
|
Why does the `users` command return different users depending on whether I ssh or open a new terminal?
|
That is normal.
The seat is all of the hardware devices that are in your workspace which is in your case, is seat0 as you are logged into a Gnome session whereas tty2 or the terminal is what is being used to run firefox. In your case tty2 is attached to seat0. If you were to log in via SSH, there would just be pts/0 (assuming that it was only you who had logged in) and no seat because pts doesn't have one.
|
I noticed by chance today that I had 2 users running on my Linux system.
I do not know much about Linux users but I ended up running the “w” command that gave the following output when Firefox is running:
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
main seat0 login- 17:22 0.00s 0.00s 0.00s /usr/libexec/gdm-wayland-session --register-session gnome-session
main tty2 tty2 17:22 8:01 2:50 0.21s /usr/lib64/firefox/firefox -contentproc -childID 28 -isForBrowser -prefsLen 30120 -prefMapSizI would like to ask the following:Is it ok to have my username being mentioned twice? IE this is not a hack into my system or anything?I assume “/gdm-wayland-session --register-session gnome-session” represents me logged into Rocky and this is normal - is this correct?I dont understand why there would be a second instance of my username associated with “/usr/lib64/firefox/firefox” - I would assume there would be a single user “main” that is running firefox, not firefox running as second instance of my user name. Is this ok / normal? Is there anything to be concerned about here?Thanks ahead of time…
|
My username mentioned twice in who command
|
Just parse the output of who:
#!/usr/bin/env bashnum=$(who | sort -uk1,1 | wc -l)
date +"Today %d %B, there are $num users logged in onto the system"Explanation
sort -uk1,1 : the -k1,1 means "sort on the 1st field and only on the first field". The -u means "print only the unique sort fields". Together, they will print one line for each user found.
Piping the above to wc -l will print the number of lines which is the number of unique users. Note that -u is a GNU extension but since you're using date -d which is also GNU, I will assume you are using the GNU versions of the tools.
|
I have the following script.
#!/bin/bash
#Solution script1who
date +"Today %d %B, there are $# users logged in onto the system"In the background user1 has logged in onto tty2 and tty3 and root has logged in onto pts/0 and tty1. The answer then should be Today 22 Oktober, there are 2 users logged in onto the system.
|
Scripting: Counting users logged in onto the system
|
Take a look at the man page for who. e.g. "If FILE is not specified, use /var/run/utmp."
This is not a text file, so opening with vi will offer a poor view of the file contents. od -c /var/run/utmp | more would serve better.
|
I would like to know how the command "who" pulls out information about ssh history into a Linux system. For example, on my shared-network workstation, where everyone can ssh into it:
[johny@gandor ~]$ who
johny :0 2018-08-30 06:44 (:0)
johny pts/0 2018-08-30 06:45 (:0.0)
johny pts/1 2018-08-30 06:45 (:0.0)
Keiven pts/2 2018-08-30 19:46 (:50.0)
seman pts/6 2018-08-31 15:15 (:50.0)
johny pts/7 2018-08-31 15:51 (:50.0)
casper pts/8 2018-08-31 16:53 (:50.0)
johny pts/10 2018-09-01 06:25 (:50.0)I think that this information is, originally, stored somewhere in Linux system files and the command "who" reads that information from that file? if so, where is that file located?
|
Source of information - command who
|
You're referring to the text at the end of the line. That is written by screen to indicate which pseudo-terminal connection it is using, as well as which window-number screen has assigned to it. Comments in the code indicate what it does:
/*
* Construct a utmp entry for window wi.
* the hostname field reflects what we know about the user (display)
* location. If d_loginhost is not set, then he is local and we write
* down the name of his terminal line; else he is remote and we keep
* the hostname here. The letter S and the window id will be appended.
* A saved utmp entry in wi->w_savut serves as a template, usually.
*/and later
/*
* we want to set our ut_host field to something like
* ":ttyhf:s.0" or
* "faui45:s.0" or
* "132.199.81.4:s.0" (even this may hurt..), but not
* "faui45.informati"......:s.0
* HPUX uses host:0.0, so chop at "." and ":" (Eric Backus)
*/concluding with the actual code which you might recognize: sprintf(host + strlen(host), ":S.%d", win->w_number); strncpy(u.ut_host, host, sizeof(u.ut_host));which stores the string in the ut_host member of the utmp/utmpx structure.
Further reading:utmp, wtmp - login records
who - show who is logged on
|
The X window system in a desktop Linux (where just one physical monitor is used) usually uses display 0, screen 0.
The output of who in Ubuntu 14.04 is
user1 :0 2016-06-15 14:25 (:0)where :0 is the abbreviation for :0.0 (:display.screen). Here I logged in only from the GUI.
Then I opened a terminal emulator; I ran screen and I created two different windows (each of them simply contained bash). The resulting output of who was:
user1 :0 2016-06-15 14:25 (:0)
user1 pts/1 2016-06-15 14:26 (:0)
user1 pts/11 2016-06-15 16:31 (:0:S.0)
user1 pts/11 2016-06-15 16:31 (:0:S.1)Why is this syntax used? It seems to be :display:display.screen.
Does screen emulate another display inside the physical display?
|
Display used by screen in utmp
|
This is probably due to a locale change:
$ locale | grep LC_TIME
LC_TIME="en_GB.UTF-8"
$ who -b
system boot 2013-11-04 10:04
$ LC_TIME=C who -b
system boot Nov 4 10:04Perhaps your locale was changed, and didn't take effect until after the reboot (perhaps you didn't update your environment after the change). As for why it looks different in a daemon, it probably has a different value for LC_TIME, or no value at all.
You can get the date using something like this (optionally replacing en_GB.UTF-8 with any locale that results in this format, since you may not have that locale on your system):
$ LC_TIME=en_GB.UTF-8 who -b | awk '{ print $3 " " $4 }'
2013-11-04 10:04
|
I run who -b to get the date of the last reboot. It returns 2013-10-29 14:55.
Now ran by a daemon (I am sending this date to a server) it returns Oct 29 14:55. But some other times (before last reboot in Oct 29) it would return something like 2013-10-24 13:17 consistently.
First set of questions :
What in an environment controls this ? Why is it different from the sudo user and the daemon ? And why did it change in between 2 reboots ?
Another question :
Is there a way to have this date with format 2013-10-29 14:55 ? I could format it but the year is missing. (i.e do you know what flag to pass who -b) ?
|
who -b date format varies strangely
|
You can find additional information about your system's command-line tools and their parameters by looking at their "man page" (by running man who, for example).From the respective man pages:top - display Linux processeswho - show who is logged onWhile we're at it, there is also:w - Show who is logged on and what they are doing.A user is "logged on" when they have performed a "login", that is they have provided a password or key to authenticate to the system, and the system has launched a "session" for them.
As you can see, who only lists these login sessions — usually together with what the session is attached to, such asan Xserver session (e.g. :0 for the first graphical session),
a terminal (tty, e.g. Ctrl+Alt+F2),
or a pseudo-terminal (pts, e.g. for an SSH session, terminal emulator or terminal multiplexer program)There are other ways to start processes that do not involve a login session, such assystem services (started by init, systemd, or whatever your system uses for service startup)
SSH sessions that did not request a tty device — this usually happens when you give a command directly after the SSH invocation (ssh example.com rsync …) instead of requesting an interactive shell (ssh example.com)
starting a process from a login session, but then detaching it from the current shell, and thereby the session (e.g. using disown)Tangentially, if you want to know what users exist on the system (both locally configured ones from /etc/passwd and any from an external database like LDAP):
getent passwdIf you also want to know when they last logged in:
lastlog
|
Working on a Raspberry Pi 2, running Raspbian GNU/Linux 9 (stretch).
I am simply trying to understand why, when I run the top command I can see some users that I cannot see in the who command. Here is output of the commands run on the RPi:
$ top
top - 12:36:42 up 2 days, 15:19, 2 users, load average: 0.29, 0.34, 0.27
Tasks: 138 total, 1 running, 73 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.0 us, 0.9 sy, 0.0 ni, 97.0 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st
KiB Mem : 949460 total, 354296 free, 62916 used, 532248 buff/cache
KiB Swap: 102396 total, 30972 free, 71424 used. 811488 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
10907 iceman 20 0 6144 3400 1924 S 2.3 0.4 4:05.37 rsync
10876 maverick 20 0 8128 3300 2740 R 1.6 0.3 0:36.49 top
376 root 20 0 911240 9648 3164 S 0.7 1.0 31:58.38 dockerd
663 root 20 0 149932 1728 1020 S 0.7 0.2 28:25.48 Xorg
674 root 20 0 884620 3848 1764 S 0.7 0.4 22:06.18 docker-co$ who
maverick pts/0 2018-11-28 11:23 (73.69.181.86)
maverick pts/1 2018-11-28 11:58 (73.69.181.86)To clarify, I have tried: who, who -u, who -l, who -p, who -a.
|
Why is top command showing users that the who command is not?
|
:0 is an X display name. This means they logged in through XDM on the :0 framebuffer.
pts/0 is a pseudo-tty, this is an xterm or gnome-terminal window.
|
When I type who in my console terminal, I get the following output:
hubert :0 2014-05-16 21:40 (:0)
hubert pts/0 2014-05-16 21:46 (:0)From info who I know that both :0 and pts/0 should name instances of the terminal. It is clear to me what pts/0 means but I have no idea how to interpret the first line of the output.
What is even more confusing, when I type who hubert :0, I get:
hubert pts/0 2014-05-16 21:46 (:0)
|
What is the :0 terminal in the who command's output? [duplicate]
|
New terminal window, I then use su - username to log in to the other userThis is your error of thinking. You are not logging in.
su does not create a login session. It is not a login mechanism. It "switches user" to run a program under the aegis of a different user account, adding privileges (that account's privileges) to the totality of privileges available to the user of the existing login session that it is run in.
The login database, reported by those various commands, lists login sessions. Adding privileges in an existing session does not change it, naturally.
(Some GUI terminal emulators, but not all, add login database entries for each emulated terminal that they provide. Yours is, but that is not su doing it. The entry is added long before you get around to running a su command in a shell using that terminal.)
Further readingJonathan de Boyne Pollard (2014). Don't abuse su for dropping user privileges. Frequently Given Answers.
Jonathan de Boyne Pollard (2018). The Unix login database. Frequently Given Answers.
https://unix.stackexchange.com/a/441817/5132
https://unix.stackexchange.com/a/283543/5132
|
Consider I have created a user 'test' during Installation which I use to login to my system. My root user is 'root'. I further open two terminal sessions for each of the users respectively. Now the problem is when I type the 'w', 'who' or even the 'finger' command (in my root terminal session) to list all users logged in, I see the 'test' user coming in two times (with different TTYs), which should have actually been 'test' & 'root'. Even If I create a new user 'test1', I still see my original username name 'test' is being the output of w, who, finger commands for users currently logged in.
Something like this:Why so?
PS.: Using RHEL7
|
Seeing user two times
|
Most simply you could make the utmp log files non-world readable. This is even mentioned in the utmp man page:Unlike various other systems, where utmp logging can be disabled by removing the file, utmp must always exist on Linux. If you want to disable who(1) then do not make utmp world readable.like this:
sudo chmod go-r /var/log/wtmp /var/run/utmp
who # shows nothing, not even an error!
sudo who # still works for root
rudi :0 2017-04-18 19:08 (console)So this would disable who completely, not only skip IP addresses.
Another idea (maybe a bit silly) to hide only the IPs could be to let your ssh server listen at another port (1234) and on localhost only. Then run a "proxy" (socat, netcat) to forward from public_ip:22 to localhost:1234:change ssh server config, /etc/ssh/sshd_config:
Port 1234
run a proxy on ssh server machine:
socat TCP-LISTEN:22,fork TCP:localhost:1234Now all utmp logs (who, last) will show the same and useless localhost IP.
Note maybe your users could still see the real connections via netstat. Instead of the userspace proxy (socat) you could also setup iptables NAT and MASQUERADING rules for the incomming ssh traffic. Or you could always use an extra "ssh hop" to always login from the same IP. This is left as an exercise for the reader. ;)
|
I am a Linux system admin, I will login every system of my local network. I don't want my IP to show up via who command.
For example, if someone enters:
$ whoit reveals my IP. Is there any way to hide my IP from the who Linux command?
[EDIT by chrips]
This is important for those concerned with their personal utility servers being hacked! Obviously, you would want to hide your current home IP from an attacker lest they find a vector on you!
|
How can I hide my IP from linux who command [closed]
|
The second field in the who command shows the console (terminal) that users are logged in on.
username tty2 2017-07-16 19:05 (:0)
|
I am in a Linux/Unix Systems class and I need to determine commands I can use to determine who is logged in on a specific terminal? I know there is the w, who, or finger commands. Do any of these commands have options to show a user on a specific terminal or type of terminal?
|
Commands I can use to determine who is logged in on a specific terminal?
|
The information about active sessions and logged in users is provided by systemd-logind (or elogind on non-systemd systems) and any user can get the information via the DBus interface:
$ busctl call org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ListUsers
a(uso) 2 1000 "jenkins" "/org/freedesktop/login1/user/_1000" 22437 "vtrefny" "/org/freedesktop/login1/user/_22437"(example from a system with two users with an active session).
The information is held by systemd so changing permissions for w/who isn't going to "disable" this. Some parts of the DBus API are protected via polkit but these are only the "active" operations like shutdown, the information about active sessions are public to everyone.
|
(Example screenshot taken from https://askubuntu.com/questions/1343872/ubuntu-shows-other-users-are-logged-in-whenever-i-shut-down-even-though-i-am-the)
But my question is: how does the system know this? I have done
sudo chmod o-r /var/run/utmp
sudo chmod o-r /var/log/wtmpAnd I verified that my user cannot run w or who anymore: the command output is empty because of read permission denied in utmp and wtmp.
So how does the system know this? Where is the information leaking?
|
"Other users are logged in" how does the system know? Where is the information leaking?
|
See here
What is the purpose of the pts directory in linux
The pts/0 is telling you which "pseudo terminal" the user was logged in on. In this case it's terminal 0,1,2 etc.
A tty is a native terminal device, the backend is either hardware or kernel emulated.
A pts (pseudo terminal device) is a terminal device which is emulated by an other program (example: xterm, screen, or ssh are such programs).
The :0 means the graphical display number, where display / screen are logical concepts of X windows system (not physical display).
|
I have 2 machine setup of rhel7 , one is in terminal mode and the other is in grahical mode , when I run 'who' command on both the machines why do I get 'tty' in 2nd column output for the machine in terminal mode and 'pts' for machine in graphical mode
|
Explain who command output in 2nd column [duplicate]
|
Taken from an answer from this question:
Historically the console was the main physical device used by the System Administrator to control the server, and TTYs were the users' serial terminals attached to a server. Now console and tty0 usually identify the same virtual device.
|
When I issue the command who in a bash terminal:
$ who
me console 2018-11-09 07:13
me ttys000 2018-11-09 07:13
me ttys001 2018-11-09 07:13The manual states:who - show who is logged on
Print information about users who are currently logged in.I am working on two terminals ttys000 and ttys001.
What does console mean in the above output?
|
The console terminal demonstrate by who
|
This is somewhat difficult to explain but /dev/pts/n are just virtual devices which only serve to move data form the keyboard to the program to standard output and aren't actual files. There will be a new pts spawned for every application you run which is why they sometimes won't match up.
|
The command w said
02:50:35 up 20:54, 10 users, load average: 1,07, 1,29, 1,41
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
myuser :0 - lun05 ?xdm? 1:38m 0.11s /bin/sh /etc/xdg/xfce4/xinitrc
myuser pts/0 - 02:06 31:29 2:45 7:35 /usr/bin/xfce4-terminal
myuser pts/1 - 02:48 1:35 0.16s 0.16s bash
myuser pts/2 - 02:48 3.00s 0.05s 0.00s w
myuser pts/3 - 02:49 0.00s 0.00s 7:35 /usr/bin/xfce4-terminal
myuser pts/5 - 02:24 0.00s 0.00s 7:35 /usr/bin/xfce4-terminal
myuser pts/7 - 01:13 0.00s 0.00s 7:35 /usr/bin/xfce4-terminal
myuser pts/8 - 01:33 0.00s 0.00s 7:35 /usr/bin/xfce4-terminal
myuser pts/9 - 01:31 0.00s 0.00s 7:35 /usr/bin/xfce4-terminal
myuser pts/10 - 18:20 0.00s 0.00s 7:35 /usr/bin/xfce4-terminalThe command who output is identical
But the pts oper are only 4
find /dev/pts/
/dev/pts/
/dev/pts/3
/dev/pts/2
/dev/pts/1
/dev/pts/0
/dev/pts/ptmxWhy w and who report 10 users and 10 pts opened?
|
who and w report my user ten times..but I have only four pts open
|
pts/1 is your pseudoterminal. A pseudoterminal provides processes with an interface that is identical to that of a real terminal.
http://linux.die.net/man/4/pts
:0 is your X11 Display
https://en.wikipedia.org/wiki/X_Window_System
|
I have just used the command 'last' to see who has logged into my server.
I am unsure how to read some of the output, particularly in Column 2 where it states pts/l and :0.
Instead of spoon feeding me the answer, could you point me in the direction of a good source or pdf's to read in order to become more familiar with this query and general ssh queries.
www.digitalocean.com has been useful up to this point.
Thanks guys( and girls).
|
how to read ssh output from 'last' and 'who' command
|
There are a number of tools to allow you to do that. Try them all:
who
w
last -p now
fingerwhich one you prefer is up to you :-)
|
In the terminal, how can I reveal the real name of the users online (with university IDs)? getent?
|
How can I reveal the real name of the users online (with university IDs)?
|
That's the display and screen information. When you're within an X session, you should find something like :0 in $DISPLAY.
This number is broken down into two parts: the first number is the display number: this generally is a group of devices that contains one or more screens, with one or more input devices. The screen number gives the specific screen being within that group.
The $DISPLAY syntax is similar to the host and port specifications that are common in networking. Fully fleshed out, it looks something like hostname:display.screen. For example, if you were referring to display 2, screen 1 on example.com, you would use the syntax example.com:2.1.
:0 is shorthand for "the first display".
|
I'm working on a script an I need to show how many people are logged into XServer. It was suggested that I look at the last part of the who command (N:N):
user1 tty7 2013-10-10 12:14 (:0)I'm trying to find information on this an having trouble finding it. Any info would be appreciated. Thanks.
|
How many XUSER's
|
If you look at the source code of the GNU implementation of who, you see: if (hard_locale (LC_TIME))
{
time_format = "%Y-%m-%d %H:%M";
time_format_width = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2;
}
else
{
time_format = "%b %e %H:%M";
time_format_width = 3 + 1 + 2 + 1 + 2 + 1 + 2;
}The declaration of hard_locale() in gnulib describes it as: /* Return true if the specified CATEGORY of the current locale is hard, i.e.
different from the C or POSIX locale that has a fixed behavior.
CATEGORY must be one of the LC_* values, but not LC_ALL. */
extern bool hard_locale (int category);So,in the C/POSIX locale, you get <EnglishMonthNameAbbreviation> <SpacePaddedDayOfTheMonth> <ZeroPaddedHour>:<ZeroPaddedMinute>
in other locales: a standard ISO8601-style YYYY-MM-DD HH:MM date.The locale for the LC_TIME category is determined by the LC_ALL env variable, or LC_TIME variable if LC_ALL is not set or LANG if neither are set. If that's C, POSIX or any string for which the system has no installed locale or if all 3 variables are unset, you get the C/POSIX locale.
The ssh command can pass the LANG and LC_* variables across to the server and it does by default on many Unix-like systems. sshd on many Unix-like systems are also configured to accept those LANG and LC_* variables by default. Microsoft Windows is not a Unix-like system though. Even if the ssh client you use there passes those variables across, it's unlikely that there be some LANG and LC_* variables in the environment containing a locale name that the server supports.
That would explain why you get the C-like date format when sshing from Windows and the ISO8601-style one when sshing from another Unix-like machine.
To get a consistent format, you can force the locale to C by running who with:
LC_ALL=C who -mBut here, it seems you rather want to extract the part between the first occurrence of ( in the line and the last occurrence of ), containing information of where the tty was logged in from, which you could do with:
who -m | perl -ne 'print $1 if /\((.*)\)/'For ttys created by sshd and provided those environment variables were not cleared (like for instance by sudo or su -), you can extract the IP address of the ssh client from the SSH_CLIENT variable, with:
ipaddress="${SSH_CLIENT%% *}"
|
If I connect via SSH to my Debian 12 Server from another Linux Server and run the who -m command, it displays the following:
test-user pts/1 2024-01-24 11:13 (xx.xx.xx.xx)But, if I connect from a Windows 11 computer, via Windows Terminal or using a third-party App to connect to the same Debian 12 Server using the same exact user and run the same who -m command, the date/time format display is different.
test-user pts/0 Jan 24 11:15 (xx.xx.xx.xx)I am running this line in the /etc/profile to determine the IP address from the user on every login, but it doesn't work properly as the output is different and those spaces are altering the outcome.
myip=$(who -m | awk '{print substr($5, 2, length($5) - 2)}')Is there a way to control the date/time output for the who command?
What could be causing this behavior?
Update
Running the locale command from:
From Linux:
$localeLANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=From Windows 11
$localeLANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=Just to note that this behavior doesn't seem to happen with all the Linux Servers I connect to. It varies and it's explained in the solution below.
As I understood the root cause as per the explanation below, I opted to use the suggestions and they both work for my use case.
|
Display consistently the date and time output for the who command
|
I got the answer here.
this would be the script to maximize it to the right half of the screen:
#!/bin/bash
# resizes the window to full height and 50% width and moves into upper right corner#define the height in px of the top system-bar:
TOPMARGIN=27#sum in px of all horizontal borders:
RIGHTMARGIN=10# get width of screen and height of screen
SCREEN_WIDTH=$(xwininfo -root | awk '$1=="Width:" {print $2}')
SCREEN_HEIGHT=$(xwininfo -root | awk '$1=="Height:" {print $2}')# new width and height
W=$(( $SCREEN_WIDTH / 2 - $RIGHTMARGIN ))
H=$(( $SCREEN_HEIGHT - 2 * $TOPMARGIN ))# X, change to move left or right:# moving to the right half of the screen:
X=$(( $SCREEN_WIDTH / 2 ))
# moving to the left:
#X=0; Y=$TOPMARGINwmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,$X,$Y,$W,$HTo move to the left, just change the X-Line to X=0. (If you use Ubuntu Unity, you need to adapt RIGHTMARGIN too I use RIGHTMARGIN=102)
defining the right margins this solves the bug, that the second time you call it, it moved to the very top of the screen, ignoring the top-toolbar.
|
I would like to resize the window to the left half of the screen.
A solution to achieve that would be to use wmctrl and keybind the right command to a keyboard shortcut.
But the manpage only shows how to resize to a certain height and width, for example:
wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz && wmctrl -r :ACTIVE: -e 0,0,0,800,1040that moves the window to the upper left corner and resizes to 800x1040 px.
But strangely only the first time. If you execute the same command again, in moves to the very top right of the screen, ignoring the top-toolbar.
Also it would be nice, to have that command with height 100% and width 50% instead of the absolute values.
|
How do I resize the active window to 50% with wmctrl?
|
Looks like the -i option in the first wmctrl cmd is causing trouble.
Try this:
wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz
wmctrl -r :ACTIVE: -e 0,300,168,740,470
|
The following script fails to resize an already maximized window:
wmctrl -i -r :ACTIVE: -b remove,maximized_vert,maximized_horz
xdotool windowunmap --sync
xdotool windowmap --sync
wmctrl -r :ACTIVE: -e 0,300,168,740,470I am pretty sure the culprit is in the middle two lines, which I am meaning to apply to the currently active window.
|
Resizing a maximized window from the command line
|
Perhaps you're getting confused with the -t # switch. The windows are numbered as starting with a 1 but the first window is actually number 0. Notice in the output of wmctrl -l:
$ wmctrl -l
0x00c00028 -1 grinchy Top Expanded Edge Panel
0x0120001e 0 grinchy x-nautilus-desktop
0x06015fee 0 grinchy saml@grinchy:~
0x06000004 0 grinchy saml@grinchy:~
0x05a000d1 0 grinchy xorg - How can I get information about my virtual desktops via the command line? - Unix & Linux Stack Exchange - Google ChromeThe 2nd column is the number of the desktop. So when you're using -t 2 it's actually putting the window -r 0x03e00003 on the 3rd desktop, not the 2nd.
Example
Evince PDF window starts on desktop #1 (0):
$ wmctrl -l | grep 0x03a00003
0x03a00003 0 greeneggs.bubba.net Packt.Puppet.3.Beginners.Guide.pdfMove it to desktop #3 (2):
$ wmctrl -i -r 0x03a00003 -t 2Confirm:
$ wmctrl -l | grep 0x03a00003
0x03a00003 2 greeneggs.bubba.net Packt.Puppet.3.Beginners.Guide.pdfNotice which window it's on though:It's on desktop #3!
ReferencesHow can I get information about my virtual desktops via the command line?
|
Currently I have successfully used wmctrl -r :SELECT: -t 2 but something like wmctrl -r -i 0x03e00003 -t 2 does not work. How should I write the command in order to select the window to be moved by ID not by mouse?
I am using Linux Mint 13 with the default MATE DE .
I have also tried wmctrl -i -r 0x03e00003 -t 2
EDIT1: wmctrl -i -r thewinIDInHexa -t 2 works now. The reason why it did not work is that while the first time i experimented with wmctrl i used the right ID but wrong syntax, the 2nd time i used the correct form but the wrong window ID... the thing is the ID was non-existent and wmctrl does not output any message for non-existent IDs. Thank you for your efforts. Having confirmation that i was in fact using the right form for the command pushed me to double check the IDs. Thank you again
EDIT2: since i am unable to comment i will post here the response to @slm :
the correct ID now is 0x0380000f
wmctrl -v -i -r 0x0380000f -t 2envir_utf8: 1
Using window: 0x0380000fVLC is moved to workspace #2 (3rd workspace)
for the ID that is actually non-existent we have pretty much the same thing:
wmctrl -v -i -r 0x03a00003 -t 2 envir_utf8: 1
Using window: 0x03a00003
|
How to move a window to a different workspace using its ID, in bash?
|
A simple tool is the import command from ImageMagick. Simply provide an output filename:
$ import /tmp/out.pngand it will grab the mouse and show an appropriate cursor. Press button 1 and drag out a rectangle which will be shown as a wire frame. Let go and the file will be created. You can get the info from this file:
$ identify /tmp/out.png
/tmp/out.png PNG 1515x14 1920x1080+24+15 ...The rectangle in this example was 1515 by 14 pixels, with top-left offset of 24 and 15 on the screen.
To extract a geometry string:
$ identify /tmp/out.png | perl -ne '/ (\d+x\d+) \d+x\d+([-+]\d+[-+]\d+) / and print "$1$2\n"'
1515x14+24+15Everything in one line:
import PNG:- | identify PNG:- | perl -ne '/ (\d+x\d+) \d+x\d+([-+]\d+[-+]\d+) / and print "$1$2\n"'Or just with ImageMagick (no perl, sed, grep, awk, etc.)
and using native ImageMagick format:
import MIFF:- | convert MIFF:- -format "%wx%h%X%Y\n" info:EDIT: It works even without piping to convert, so:
import -format "%wx%h%X%Y\n" info:
|
I would like to execute a command-line command that activates "click and drag" mouse selection on a single local X11 screen.
The goal is to:get the selected rectangle X and Y coordinates,
get the rectangle width and height,
output these values to stdout,
(optional) draw a selection border while dragging the mouse.
|
Command-line tool to get "click and drag" rectangle coordinates from the screen [duplicate]
|
You can use xdotool like that:
xdotool search "Mozilla Firefox" windowminimize
|
I have a startup application that has no option to "start minimized" or "close to system tray" etc. and therefore would like to use a startup script that will first start the application and then minimize its window.
Actually, I already have a startup script that closes the window of an application which luckily has a sort of "close to system tray" option:
wmctrl -ic $(wmctrl -l | grep "AppWindowTitle" | cut -d ' ' -f 1)I should ideally be able to minimize the window with a command like this:
wmctrl -ir $(wmctrl -l | grep "AppWindowTitle" | cut -d ' ' -f 1) -b toggle,minimizedBut there is not such option available in wmctrl. Options for the first argument are: add, remove, toggle. And options for the second argument are: modal, sticky, shaded, skip_taskbar, skip_pager, hidden, fullscreen, above, below, maximized_vert, maximized_horz
These seem to work and I would expect the argument hidden could be the one I need but it's not hiding the window.
I wonder if there's some other way of achieving this...
|
How to minimize an application window from command line
|
Yes, it is possible. The idea is to ask kwin for this information. It is done via kwin script. It can only communicate the world with dbus, so we cannot run shell commands in kwin scripts (at least directly). But we can run kwin script from shell script.
Create the following script ~/bin/list_windows.js:
const clients = workspace.clientList();
for (var i = 0; i < clients.length; i++) {
print(clients[i].caption);
}Unfortunately, the output to stdout is currently broken, see bug report. But there is a workaround. Turn on the kde systemd startup. Now we can use journalctl to pull the output. The resulting get_list_of_windows script is the following:
#!/usr/bin/env python3import subprocess
from datetime import datetimedef get_list_of_windows():
datetime_now = datetime.now() script = "/home/andrew/bin/list_windows.js" reg_script_number = subprocess.run("dbus-send --print-reply --dest=org.kde.KWin \
/Scripting org.kde.kwin.Scripting.loadScript \
string:" + script + " | awk 'END {print $2}'",
capture_output=True, shell=True).stdout.decode().split("\n")[0] subprocess.run("dbus-send --print-reply --dest=org.kde.KWin /" + reg_script_number + " org.kde.kwin.Script.run",
shell=True, stdout=subprocess.DEVNULL)
subprocess.run("dbus-send --print-reply --dest=org.kde.KWin /" + reg_script_number + " org.kde.kwin.Script.stop",
shell=True, stdout=subprocess.DEVNULL) # unregister number since = str(datetime_now) msg = subprocess.run("journalctl _COMM=kwin_wayland -o cat --since \"" + since + "\"",
capture_output=True, shell=True).stdout.decode().rstrip().split("\n")
msg = [el.lstrip("js: ") for el in msg] return msgprint('\n'.join(get_list_of_windows()))Now run the script and you will get the output:
$ get_list_of_windows
Рабочий стол по умолчанию — Plasma
Plasma
Is there a way to get list of windows on KDE Wayland? - Unix & Linux Stack Exchange - Vivaldi
get_list_of_windows — Kate
Andrew Shark / Davinci Resolve Scripts · GitLab — Falkon
project1 – README.mdThis is in my repo.
|
In the era of X11, I could do wmctrl -l to list available windows, that I can use in my scripts.
$ wmctrl -l
0x01000050 0 my-pc project1 – Readme.mdBut nowadays most application use Wayland. The above command only shows windows that are running with XWayland.
I want to be able to use applications in Wayland mode and at the same time be able to list their windows for my scripts. Is that possible? I am using Arch Linux with KDE.
|
Is there a way to get list of windows on KDE Wayland?
|
To get the Window ID in my program, I have the program set the title to something unique, then have the program start wmctrl and parse its output (and not the shell script that started the program), and then report on the Window ID (most often via a file).
Since the program doesn't continue until the windows are open, you will never have to wait to long.
This of course requires that you can change myprogram ( ie. compile from source).
|
I want to retrieve the X id of GUI programs I launch in background, in order to work on their windows properties. I've been so far using this workaround:
myprogram &
sleep 1
winID=$(wmctrl -l | awk '/./{line=$0} END{print $1;}')But this relies on three heavy assumptions:the program will take less than 1 second to get its window opened (not to mention than 1 second can be far too long)
the window will be appened at the end of the wmctrl list
no other window will be opened meanwhileIs there any signal myprogram will send once it has opened a window? How can I intercept it?
|
Retrieve X11 window ID of a just-launched GUI-program
|
wmctrl -lpG \
| awk '{
tmp=$0;
# remove first 8 fields from tmp
sub(/^[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ +[^ ]+ /,"",tmp);
print "----------------------\nWindow ID: " $1 "\nDesktop Number: " $2 "\nProcess ID: " $3 "\nx-offset: " $4 "\ny-offset: " $5 "\nwidth: " $6 "\nheight: " $7 "\nMachine Name: " $8 "\nWindow Title: " tmp
}'Output:
----------------------
Window ID: 0x0120002b
Desktop Number: 4
Process ID: 7
x-offset: 2
y-offset: 157
width: 3836
height: 2068
Machine Name: sidekick
Window Title: window - AWK - Dealing with spaces in the last column of output from wmctrl - Unix & Linux Stack Exchange — Firefox
|
As a first project for learning awk, I wanted to reformat the output of the wmctrl command, which can be installed like this in Debian 11:
sudo apt install wmctrlTo list information about all the windows I have open, I run this command:
wmctrl -lpGSample Output:
0x0120002b 4 7 2 157 3836 2068 my-pc window - AWK - Dealing with spaces in the last column of output from wmctrl - Unix & Linux Stack Exchange — FirefoxI never can remember what each column means, in the command above, so I wanted to break it apart into name/value pairs, using AWK:
wmctrl -lpG | awk '{print "----------------------\nWindow ID: " $1 "\nDesktop Number: " $2 "\nProcess ID: " $3 "\nx-offset: " $4 "\ny-offset: " $5 "\nwidth: " $6 "\nheight: " $7 "\nMachine Name: " $8 "\nWindow Title: " $9}'Sample Output:
----------------------
Window ID: 0x0120002b
Desktop Number: 4
Process ID: 7
x-offset: 2
y-offset: 134
width: 3836
height: 2068
Machine Name: my-pc
Window Title: windowDesired Output:
----------------------
Window ID: 0x0120002b
Desktop Number: 4
Process ID: 7
x-offset: 2
y-offset: 134
width: 3836
height: 2068
Machine Name: my-pc
Window Title: window - AWK - Dealing with spaces in the last column of output from wmctrl - Unix & Linux Stack Exchange — FirefoxHowever, I'm having trouble figuring out how to handle the 9th Column outputted by wmctrl -lpG (because the 9th column contains spaces). Notice that I'm only getting the first word of the window title instead of the whole window title.
Is there an easy way to remedy this issue?
|
AWK - Dealing with spaces in the last column of output from wmctrl
|
The -i option needs a window id, which is what you get if you just run
xdotool getactivewindowwhich prints a decimal number like 20971543. So you can do
wmctrl -i -r "$(xdotool getactivewindow)" ...But you don't need to do this as wmctrl accepts a pseudo-window id string of :ACTIVE: to mean the focused window, so you can do
wmctrl -r :ACTIVE: ...
|
I am using a 21:9 Monitor and wrote a script to tile/align my windows to the left, centre and right side of the monitor, using keyboard-shortcuts:
┌─────────┬─────────┬─────────┐
│ window1 │ window2 │ window3 │
│ left │ centre │ right │
│ aligned │ aligned │ aligned │
└─────────┴─────────┴─────────┘The script works by getting the name of the currently focused window:
WINDOW_NAME=$(xdotool getwindowfocus getwindowname)
and aligns the window using its window name:
wmctrl -ir "$WINDOW_NAME" -e 1,$X_OFFSET,$Y_OFFSET,$X_WIDTH,$Y_HEIGHT
The problem is, when having several windows opened with same window name (e.g. 2 Firefox browsers or 3 Terminals etc.), it does not move the current focused window, but from all windows with the same name, the one which was opened the first.
I.e. Let's say I open 3 Terminals, and I want do align Terminal T2, the script will align T1 not T2, because T1 was opened first.
So my idea is instead of using the window names, using the process IDs (PIDs), because unlike the name of a window, the PID is unique.
The question is: Is it possible to work with wmctrl using PIDs?
In the man pages of wmctrl I found the option -i which interprets the variable <WIN> as a number instead of a string-name.
$ man wmctrl
[...]
-e <MVARG>
Resize and move a window that has been specified with a -r
action according to the <MVARG> argument.
[...]
-r <WIN>
Specify a target window for an action.
[...]
-i
Interpret window arguments (<WIN>) as a numeric value rather
than a string name for the window. If the numeric value starts
with the prefix '0x' it is assumed to be a hexadecimal number.
[...]I don't really understand what this -i option means, and thought maybe this means it is possible to use the PID instead of the window-name:
WINDOW_ID=$(xdotool getactivewindow getwindowpid)
WINDOW_ID=$(printf 0x%x $WINDOW_ID)
wmctrl -ir "$WINDOW_ID" -e 1,$X_OFFSET,$Y_OFFSET,$X_WIDTH,$Y_HEIGHTUnfortunately this didn't work (neither with decimal, nor as hex number).
Q1: Is it possible to use wmctrl with PIDs instead of window-names?
Q2: What does the -i option actually mean?
|
How to resize and move a window by its PID using `wmctrl`?
|
I found a related question on Ask Ubuntu which sort of did the trick for me. Instructions for the whole process, including creating the "gap" between monitors (works at least on Ubuntu 14.04):Find out the current total screen size (assuming there's currently no virtual gap between monitors):
$ xrandr | grep Screen
Screen 0: minimum 320 x 200, current2048 x 1280, maximum 32767 x 32767
Add the desired gap size in pixels to the width (first value displayed after current – in my case, 2048). I chose a gap of 136 pixels, so I'd have a new screen width of 2184.
Set the new screen size:
xrandr --fb 2184x1280
Find out the display name of your right monitor:
$ xrandr | grep ^[^\(]*right
HDMI3connected 1024x1280+1024+0 right (normal left inverted right x axis y axis) 376mm x 301mm
Virtually move the right monitor further to the right to create the gap. Add your gap size to the third number displayed by the above command (highlighted in bold). In my example, this is 1024+136=1160:
xrandr --output HDMI3 --pos 1160x0Now, make Compiz handle the whole area as one single screenStart CompizConfig Settings Manager (installable with sudo apt-get install compizconfig-settings-manager)
Go to "General Options" plugin (e.g. type this in search box)
Select tab "Display Settings"
Uncheck "Detect Outputs"
If this doesn't already do the trick, right click on each line listed under "Outputs", select "Edit" and delete their content.When maximizing a window, it will now stretch both monitors. Fullscreen will also stretch both monitors.
Clearly, this isn't ideal, as most of the time it is desirable that maximized windows fill a single monitor. This means, the "Detect Outputs" Compiz option will have to be checked and unchecked depending on what behavior is currently desired.
A note to user with non-English locale: If you can't find the CompizConfig plugin and setting because you don't know how their names were translated, start CompizConfig like so:
LANG=C ccsm
|
I have a dual monitor setup with Compiz as window manager on Ubuntu 14.04. I can resize a window to stretch over both windows. However, while the physical display panels are a few centimeters apart, the software by default thinks of them to be right next to each other without a gap in between. This means, e.g. a diagonal line ends up looking like this:
+----------+ +----------+
| | | / |
| | | / |
| | | / |
| | |/ |
| /| | |
| / | | |
+----------+ +----------+What I'd like to achieve is something more like this:
+----------+ +----------+
| | | / |
| | |/ |
| | | |
| | | |
| /| | |
| / | | |
+----------+ +----------+This would result in part of the window being hidden, but that's acceptable.
I can make X regard the displays to have a gap in between as follows:
$ xrandr
Screen 0: minimum 320 x 200, current 2048 x 1280, maximum 32767 x 32767
LVDS1 connected (normal left inverted right x axis y axis)
1366x768 60.0 +
1360x768 59.8 60.0
1024x768 60.0
800x600 60.3 56.2
640x480 59.9
VGA1 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 disconnected (normal left inverted right x axis y axis)
HDMI2 connected primary 1024x1280+0+0 left (normal left inverted right x axis y axis) 376mm x 301mm
1280x1024 60.0*+ 75.0
1280x960 60.0
1152x864 75.0
1024x768 75.1 70.1 60.0
832x624 74.6
800x600 72.2 75.0 60.3 56.2
640x480 75.0 72.8 66.7 60.0
720x400 70.1
HDMI3 connected 1024x1280+1024+0 right (normal left inverted right x axis y axis) 376mm x 301mm
1280x1024 60.0*+ 75.0
1280x960 60.0
1152x864 75.0
1024x768 75.1 70.1 60.0
832x624 74.6
800x600 72.2 75.0 60.3 56.2
640x480 75.0 72.8 66.7 60.0
720x400 70.1
DP2 disconnected (normal left inverted right x axis y axis)
DP3 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)
$ xrandr --fb 2184x1280
$ xrandr --output HDMI3 --pos 1160x0At first sight, this seems to work perfectly – when I move the mouse in a diagonal line across the gap between the monitors, it disappears "behind" the monitor bezels and re-appears where I'd expect the diagonal line to continue.
However, I can no longer move or resize a window to stretch across both monitors. Neither the mouse nor wmctrl seem to be able to do that.
Is there a way to achieve what I want?
|
Stretch window over two monitors with "gap" in between
|
There's several ways to do it. Depending on your preferred type of tool, you might choose one over other
AWK
Most appropriate way. Set words 1,2,3 to empty string and print
$ wmctrl -l | awk '{$1=$2=$3="";print}' Alternatively to get rid of leading space, you can do this:
$ wmctrl -l | awk '{for(i=4;i<=NF;i++) printf "%s ",$i;print ""}'cut
A little awkward approach, we print everything after specific field till field 9999. Why 9999 ? -f flag apparently needs to know range, so with input that have arbitrary number of words per line, we obviously can't know the range, but we can use something sufficiently large, hence 9999.
$ wmctrl -l | cut -d " " -f 5-9999Perl
We can take advantage of -a autosplit mode, where words of each line read from stdin are split into array. This potentially could be improved and shortened.
$ wmctrl -l | perl -lane 'my $numels=scalar @F;print @F[3..$numels]'Python
Slightly lengthy but works. Python doesn't have auto split mode like perl , but we can do so manually on each string read.
$ wmctrl -l | python -c "import sys; print '\n'.join([' '.join(line.split()[3:]) for line in sys.stdin])"Alternatively we can use a short script for to simulate cut, instead of one-liner. This would work much better for multiline texts/inputs and is much more readable
#!/usr/bin/env python
import sysstart=int(sys.argv[1])
for line in sys.stdin:
print " ".join(line.strip().split()[start:])And call it as so:
$ wmctrl -l | ./print_words.py 3SED
This way takes advantage of regular expressions. We match string from the beginning of line ^ till word boundary parrot with \b and following space, and delete them (effectively setting to null string)
$ wmctrl -l | sed 's/^.*\bparrot\ //'Alternatively to avoid greedy matching, we can use the following:
$ wmctrl -l | sed 's/^[^ ]* *[^ ]* *[^ ]* //'The pattern isn't too complex.We start matching at beginning of the line, and matching any number of characters (the * part) that are not space ([^ ] part) three times separated by any number of spaces. So ^[^ ]* matches first word, * matches any number of spaces, second [^ ]* matches second word, and second * matches second space, finally with [^ ]* matching 3rd word plus space.
BASH + xargs
We can take advantage of bash's ability to iterate over command-line arguments, and pass each line ( -L 1 ) as set of command-line arguments to bash -c ' '. The rest is simple - we get rids of first 3 arguments, and print the rest
wmctrl -l | xargs -L 1 bash -c 'for i in 1 2 3;do shift ; done ; printf "%s " "$@";printf "\n"' shAlternatively, as suggested by Stephane Chazelas in the comments: as long as there are at least 3 positional arguments being passed from wmctrl -l (which in this case should be consistently true), the solution can be shortened to :
wmctrl -l | xargs -L 1 bash -c 'shift 3;printf "%s " "$@";printf "\n"' sh
|
I am trying to just get the application name out of this code:
wmctrl -lbut I don't know how to do it!
If you could please explain how I could do this, that would be great.
EDIT:
The output of wmctrl -l is:
0x01000007 -1 parrot Top Expanded Edge Panel
0x01000017 -1 parrot Bottom Expanded Edge Panel
0x01200006 -1 parrot x-caja-desktop
0x03600006 0 parrot Terminal
0x03000130 0 parrot scripting - Getting a string after a word in BASH - Unix & Linux Stack Exchange - Google Chromeso I need everything after parrot
|
Getting just the application name from wmctrl -l
|
From the documentation of -t <DESK>:Move a window that has been specified with the -r action to the desktop <DESK>.Thus:
wmctrl -i -r 0x03e00057 -t 3-i means that any argument that specifies a window is a window ID rather than a substring of the window title. It's a simple option, not followed by a window ID. It applies to the <WIN> argument of -c, -r, -R`, etc.
|
I am trying to use wmctrl to move a window to a workspace.
By wmctrl -l window is
0x03e00057 9 meer montazo - Google Search — Mozilla FirefoxCommand and output is
/usr/local/bin/wmctrl -v -i 0x03e00057 -t 3
envir_utf8: 0
No window was specified.My understanding is that -i points to the hex id of the window (first field in the output list?), which in my simple mind i am doing here. Where am I astray?
|
wmctrl move window to workspace
|
A simple way to do this is with the xprop standard X11 utility. You provide a means of identifying the window, by window id, window name, or interactively by clicking on it, and it shows the X11 properties of that window. Adding the option -spy will make it loop waiting for changed-property events, which it will display. This is not a busy loop, but uses the standard X11 mechanism to wait for asked-for events. When the window dies, the event queue gets closed, and xprop ends cleanly. For example,
xterm -title mytest -e 'sleep 5' &
sleep 1
xprop -spy -name mytest
echo "rc=$? xterm done"Typically, only a few properties ever change, such as when the window is iconised.
|
I'm running Ubuntu 20.04.5 LTS with the XFCE4 window manager.
I'm looking for a way for a shell script to be fired off when a particular X Window has been closed.
I know that I can create a program to run wmctrl or xdotool over and over again in a loop that checks for the existence of the X Window in question, and then executes a shell script when the presence of that X Window is no longer detected.
But I'm wondering whether there might be some sort of event-based utility that I can run which can do some or all of this for me, instead of my having to write this busy-wait-based program.
Any suggestions?
Thank you in advance.
|
Detecting when an X Window has been closed
|
The && concatenation operator causes the second command not to be executed until after the first command (xfce4-terminal) exits (and only if the exit status indicates success, since it is a short-circuit logical operator).
You should get the behavior you expect if you change && to ; or simply place the wmctrl command on a separate line of your script.
|
If I type these two commands in a terminal:
xfce4-terminal --hide-menubar --hide-borders --hide-toolbars --title=dt
wmctrl -r dt -e 0,10,10,720,720I get the desired result (position and resize of window with title dt, noting than unlike gnome-terminal, xfce4-terminal doesn't rewrite manually assigned titles)
Naturally I would expect this to work:
#! /bin/bash
xfce4-terminal --hide-menubar --hide-borders --hide-toolbars --title=dt && wmctrl -r dt -e 0,10,10,720,720The terminal displays itself with the correct settings and title but wmctrl is having no effect whatsoever.
|
WMCTRL not working after starting xfce4-terminal
|
No, wmctrl doesn't have ability to send keystrokes in the sense of typing out letters and key combinations. There is -c flag for closing window, which can be used to emulate Ctrl+F4 for closing a window, but that's a stretch of reasoning.
You can combine those, of course, although wmctrl refers to window XIDs in hexadecimal format,so you may have to make conversion between those. xdotool alone, however, is sufficient to send keystrokes to specific windows.
|
Is it possible using wmctrl to send keystrokes to a window? I know it's possible by using xdotool. Both tools are very similar, so maybe I missed something when I read the man pages for wmctrl.
|
Sending key with wmctrl
|
It's often the case that in Unix you can chain commands together, and often times many commands are built specifically so that they'll work with the output generated by other commands.
Luckily you can take the output of xlsclients and parse it down so that it's just the name of the command. You can then pass this info to the ps command to get the output you're looking for:
$ xlsclients
dufresne conky -c /home/slm/.conky/b.conf
dufresne cinnamon-session
dufresne cinnamon-settings-daemon
dufresne csd-locate-pointer
dufresne clipit$ xlsclients | cut -d" " -f3 | paste - -s -d ','
conky,cinnamon-session,cinnamon-settings-daemon....You can then give this list of process names to the -C switch of ps.
$ ps -o pid,comm,pmem,pcpu,uname \
-C $(xlsclients | cut -d" " -f3 | paste - -s -d ',')NOTE: We've removed the -e switch since we're now providing a list to ps.
Example
$ ps -o pid,comm,pmem,pcpu,uname \
-C "$(xlsclients | cut -d" " -f3 | paste - -s -d ',')" | head
PID COMMAND %MEM %CPU USER
1998 cinnamon-launch 0.2 0.0 slm
2031 cinnamon 6.5 0.7 slm
16736 cinnamon-launch 0.3 0.0 slm
16738 cinnamon 6.1 2.7 slm
16994 cinnamon-sessio 0.2 0.0 slm
17231 cinnamon-settin 0.4 0.0 slm
17293 csd-locate-poin 0.2 0.0 slm
17331 nm-applet 0.3 0.0 slm
17339 clipit 0.2 0.1 slm
|
I want to list main applications processes report in this format
ps -e -o pid,comm,pmem,pcpu,unameTo filter main GUI applications wmctrl -pl is the only way I can get processes ids.its great if xlsclients can be used. It contains the real list with names I want.
How can I combine them as single commands to get report as I want. (ps -p = xlsclients -p)
|
Get report of the gui application processes
|
There is no supported working solution for Gnome 3.14 in Debian 8.5.
Let's hope the next release of Gnome at Q1-Q2 2017 will help the case.
|
I have many figures of widthxheight (550-570)x(465-486) at the southwest logically set there by Matlab's movegui() function.
I would like to open all those southwest windows of the size range in an external display or in Workspace 2.
Meuh's command shows those figure dimensions width x height, their hex codes and titles where I would like to move windows of size 560 x 475 for width x height, respectively, to Workspace 2
masi@masi:~$ wmctrl -l -G
0x01c0000b 0 0 0 3840 1080 masi Desktop
0x01e00002 0 0 54 1920 1023 masi Edit - Unix & Linux Stack Exchange - Google Chrome
0x02200006 0 2088 333 1608 501 masi masi@masi: ~
0x0280003d 0 1920 78 1920 1041 masi MATLAB R2016a - academic use
0x02800ac6 0 11 113 568 465 masi Figure 1: data gray all 4
0x02800af2 0 687 113 560 475 masi Figure 2: data gray top half (1/2)
0x02800aff 0 1364 113 560 475 masi Figure 3: data gray top #1 (1/4)
0x02800b16 0 1364 621 560 475 masi Figure 4: Time domain
0x02800b2a 0 11 631 568 465 masi Figure 5: Memory/... Monitoring
0x02800b31 0 683 631 568 465 masi Figure 6: data Size(I) monitoring
0x02800b3b 0 11 621 560 475 masi Figure 7: Histograms
0x02800b85 0 774 594 386 28 masi Press SPACEBAR to continueDoing meuh's command gives the correct number of wmctrl commands but individual commands do not have any effect (beware different hex-codes here than above because different iteration)
masi@masi:~$ wmctrl -l -G |
> awk '$0~/^0x/{ winid=$1; width=$5; height=$6;
> if(width>=550 && width<=570 && height>=465 && height<=485)
> printf "wmctrl -i -r %s -t 2\n",winid
> }' | sh -x
+ wmctrl -i -r 0x03200120 -t 2
+ wmctrl -i -r 0x03200149 -t 2
+ wmctrl -i -r 0x0320015f -t 2
+ wmctrl -i -r 0x03200173 -t 2
+ wmctrl -i -r 0x03200188 -t 2
+ wmctrl -i -r 0x0320019f -t 2
+ wmctrl -i -r 0x032001b2 -t 2Why the commond + wmctrl -i -r 0x03200120 -t 2 putting the window to Workspace 2? What is the symbol + there?I do wmctrl -r 1 -t 2 but nothing, TODO specify somehow dimensions here.
How can you move windows of size 560x475 to Workspace 2?
How can move windows of size (550-570)x(465-485) to Workspace 2?OS: Debian 8.5 64 bit
Linux kernel: 4.6 of backports
Matlab: 2016a
Window manager: Gnome 3.14
Hardware: Asus Zenbook UX303UA, Asus PC
Other sources: Commandlinefu search wmctrl does not bring anything relevant
|
How to move windows of dimension range to Workspace 2?
|
This will replace the pid in wmctrl -lp’s output with the corresponding command, if one is found:
wmctrl -lp | awk '{ pid=$3; cmd="ps -o comm= " pid; while ((cmd | getline command) > 0) { sub(" " pid " ", " " command " ") }; close(cmd) } 1'This obviously won’t work for windows displaying remote processes; it also will give strange results for windows corresponding to sandboxed processes in some cases (e.g. Flatpak).
The AWK script reads each line, extracts the pid, and runs ps -o comm= to determine the corresponding command; if one is found, it replaces the corresponding pid string with the command.
|
You can list the process ID of each widow with this command:
wmctrl -lpDoes there exist a command that shows the running command of each window (kind of like htop has a column for "Command")?
If not, how could you combine commands to ultimately achieve this?
|
List Running Commands of All Windows
|
You syntax for the command is wrong, use:
wmctrl -r :ACTIVE: -e 0,100,100,600,400The -r parameter expects a window name string (or :ACTIVE:) and the -e paramter expects the dimensions.
|
The following fails to resize my active window (simply nothing happens). Is there something I'm missing?
The command I used is:
wmctrl -r -e :ACTIVE: 0,100,100,600,400
|
Wmctrl Resizing Issue
|
Try using xprop to get the class of the window and then use that instead of the title, this shouldn't change any time soon.
You can run xprop | grep -i class from a terminal and then click on your Intellij IDEA window and it should print out the class in the terminal.
I have not used wmctrl, but I use the class or appid of a window in Sway to make keybinds to focus specific programs.
edit: a quick glance at the wmctrl man page shows that the -x argument may help you. "Include WM_CLASS in the window list or interpret as the WM_CLASS name."
|
I have shortcut keys setup that take the focus to a certain application in my Xubuntu setup.
So e.g.:
START+1 takes me to my main web browser window
START+2 takes me to my main Sublime window
START+3 used to take me to IntelliJ IDEA using this command set in XFCE settings editor under xfce4-keyboard-shortcuts:
bash -c 'wmctrl -a "IntelliJ IDEA" || /opt/idea-IC-202.7660.26/bin/idea.sh'
I haven't used IDEA for some time and now after upgrading I see that there is no "IntelliJ IDEA" in the title bar of the application any more - just the name of the project and optionally full path..
So my setup is broken..
Is there a way to fix it?
I am not that tough in Linux yet, but I was thinking if searching it in the process tree would help find that project name and path that in turn could be piped to wmctrl or is that even possible?
Food for thought.
Mike
|
Ubuntu: XFCE: Is there a workaround for swiching to IntelliJ IDEA with wmctrl after IDEA removed "IntelliJ" from the `window title`?
|
Seems like your root lacks some X11 magic cookie in the .Xauthority, which your standarduser has. Here is how to fix this.
SHORT VERSION (thanks to @Vladimir Panteleev)
standarduser@localhost:~$ sudo xauth add $(xauth list | grep "unix$(echo $DISPLAY | cut -c10-12)")ORIGINAL LONG VERSION
To fix things, first detect which display number standarduser uses:
standarduser@localhost:~$ echo $DISPLAY
localhost:21.0In this case it is 21.0. Secondly, display standarduser's list of cookies:
standarduser@localhost:~$ xauth list
localhost/unix:1 MIT-MAGIC-COOKIE-1 51a3801fd7776704575752f09015c61d
localhost/unix:21 MIT-MAGIC-COOKIE-1 0ba2913f8d9df0ee9eda295cad7b104f
localhost/unix:22 MIT-MAGIC-COOKIE-1 22ba6595c270f20f6315c53e27958dfe
localhost/unix:20 MIT-MAGIC-COOKIE-1 267f68b51726a8a381cfc10c91783a13The cookie for the 21.0 display is the second in the list and ends with 104f.
The last thing to do is to add this particular cookie to the root's .Xauthority. Log in as root and do the following:
root@localhost:~$ xauth add localhost/unix:21 MIT-MAGIC-COOKIE-1 0ba2913f8d9df0ee9eda295cad7b104fThis is how you can mitigate the X11 connection rejected because of wrong authentication error when you run su as a different user in Bash script or screen.
Thanks to this guy for inspiration.
|
As root, I'm connecting to a remote host to execute a command. Only "standarduser" has the appropriate id-file and correct .ssh/config, so I'm switching the user first:
su standarduser -c 'ssh -x remotehost ./remotecommand'The command works fine, but despite the fact that I used "-x" (disable X11-Forwarding) and having X11Forwards disabled in /etc/ssh/ssh_config, I still get the error message:
X11 connection rejected because of wrong authentication.I'm not getting the error message when I'm logged in as "standarduser".
This is quite annoying as I would like to integrate the command in a cron job file. I understand that the error message refers to the wrong authentication of root's .XAuth file, but I'm not even trying to connect via X11.
Why is "ssh -x" not disabling the X11 connection and throwing the error message?
UPDATE:
The message only shows when I'm logged in within a screen, when using the command stated above on the local machine itself (without screen), I don't get an error message, so this should be fine with cron, too.
I also started the same command with -v and surprisingly got the error message FIRST, even before the status information from SSH:
root@localhost:~# su standarduser -c 'ssh -x remotehost ./remotecommand'
X11 connection rejected because of wrong authentication.
OpenSSH_6.2p2 Ubuntu-6ubuntu0.1, OpenSSL 1.0.1e 11 Feb 2013This led me to the problem itself, it is NOT the ssh which is throwing the error message, it's su:
root@localhost:~# su standarduser -c 'echo Hi'
X11 connection rejected because of wrong authentication.
HiWhy do I only get this error within screen? How can I disable this error message?
|
"su" with error "X11 connection rejected because of wrong authentication"
|
Running an strace on the remote system where xauth is failing will show you what's tripping up xauth.
For example
$ strace xauth list
stat("/home/sam/.Xauthority-c", {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
open("/home/sam/.Xauthority-c", O_WRONLY|O_CREAT|O_EXCL, 0600) = -1 EEXIST (File exists)
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({2, 0}, 0x7fff6c4430e0) = 0
open("/home/sam/.Xauthority-c", O_WRONLY|O_CREAT|O_EXCL, 0600) = -1 EEXIST (File exists)
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
nanosleep({2, 0}, 0x7fff6c4430e0) = 0
open("/home/sam/.Xauthority-c", O_WRONLY|O_CREAT|O_EXCL, 0600) = -1 EEXIST (File exists)
rt_sigprocmask(SIG_BLOCK, [CHLD], [], 8) = 0
rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0So xauth is attempting to open a file and it already exists. The culprit file is /home/sam/.Xauthority-c. We can confirm the presence of this file on the remote system:
$ ls -l .Xauthority*
-rw------- 1 sam sam 55 Jul 12 22:04 .Xauthority
-rw------- 1 sam sam 0 Jul 12 22:36 .Xauthority-c
-rw------- 1 sam sam 0 Jul 12 22:36 .Xauthority-lThe fix
As it turns out. Those files are lock files for .Xauthority, so simply removing them resolves the issue.
$ rm -fr .Xauthority-*With the files deleted, exit from the SSH connection and then reconnect. This will allow xauth to re-run successfully.
$ ssh -t skinner ssh sam@blackbird
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-44-generic x86_64) * Documentation: https://help.ubuntu.com/Last login: Sun Jul 12 22:37:54 2015 from skinner.bubba.net
$Now we're able to run xauth list and X11 applications without issue.
$ xauth list
blackbird/unix:10 MIT-MAGIC-COOKIE-1 cf01f793d2a5ece0ea58196ab5a7977aThe GUI
$ xeyesAlternative method to resolve the issue
I came across this post titled: xauth: error in locking authority file .Xauthority [linux, ssh, X11] which mentions the use of xauth -b to break any lock files that may be hanging around. xauth's man page seems to back this up:
-b This option indicates that xauth should attempt to break any
authority file locks before proceeding. Use this option only to
clean up stale locks.ReferencesDealing with xauth “error in locking authority file” errors
|
While attempting to SSH into a host I received the following message from xauth:/usr/bin/xauth: timeout in locking authority file /home/sam/.XauthorityNOTE: I was trying to remote display an X11 GUI via an SSH connection so I needed xauth to be able to create a $HOME/.Xauthority file successfully, but as that message was indicating, it was clearly not.
Attempts to run any X11 based apps, such as xeyes were greeted with this message:
$ xeyes
X11 connection rejected because of wrong authentication.
Error: Can't open display: localhost:10.0How can I resolve this issue?
|
Why am I getting this message from xauth: "timeout in locking authority file /home/<user>/.Xauthority"?
|
TL,DR: it's Apparmor's fault, and due to my home directory being outside /home.
Under a default installation of Ubuntu 10.04, the apparmor package is pulled in as an indirect Recommends-level dependency of the ubuntu-standard package. The system logs (/var/log/syslog) show that Apparmor is rejecting Evince's attempt to read ~/.Xauthority:Jul 5 17:58:31 darkstar kernel: [15994724.481599] type=1503 audit(13415
03911.542:168): operation="open" pid=9806 parent=9805 profile="/usr/bin/evince"
requested_mask="r::" denied_mask="r::" fsuid=1001 ouid=1001 name="/elsewhere/home/gilles/.Xauthority"The default Evince configuration for Apparmor (in /etc/apparmor.d/usr.bin.evince) is very permissive: it allows arbitrary reads and writes under all home directories. However, my home directory on this machine is a symbolic link to non-standard location which is not listed in the default AppArmor configuration. Access is allowed under /home, but the real location of my home directory is /elsewhere/home/gilles, so access is denied.
Other applications that might be affected by this issue include:Firefox, but its profile is disabled by default (by the presence of a symbolic link /etc/apparmor.d/disable/usr.bin.firefox -> /etc/apparmor.d/usr.bin.firefox).
CUPS PDF printing; I haven't tested, but I expect it to fail writing to ~/PDF.My fix was to edit /etc/apparmor.d/tunables/home.d/local and add the line
@{HOMEDIRS}+=/elsewhere/home/to have the non-standard location of home directories recognized (note that the final / is important; see the comments in /etc/apparmor.d/tunables/home.d/ubuntu), then run /etc/init.d/apparmor reload to update the Apparmor settings.
If you don't have administrator privileges and the system administrator is unresponsive, you can copy the evince binary to a different location such as ~/bin, and it won't be covered by the Apparmor policy (so you'll be able to start it, but will not be afforded the very limited extra security that Apparmor provides).
This issue has been reported as Ubuntu bug #447292. The resolution handles the case when some users have their home directory as listed in /etc/passwd outside /home, but not cases such as mine where /home/gilles is a symbolic link.
|
I'm logged in remotely over SSH with X forwarding to a machine running Ubuntu 10.04 (lucid). Most X11 applications (e.g. xterm, gnome-terminal) work fine. But Evince does not start. It seems unable to read ~/.Xauthority, even though the file exists, and is evidently readable (it has the right permissions and other applications read it just fine).
$ evince
X11 connection rejected because of wrong authentication.
Cannot parse arguments: Cannot open display:
$ echo DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY
DISPLAY=localhost:10.0 XAUTHORITY=
$ strace evince
…
access("/home/gilles/.Xauthority", R_OK) = 0
open("/home/gilles/.Xauthority", O_RDONLY) = -1 EACCES (Permission denied)
…
$ ls -l ~/.Xauthority
-rw------- 1 gilles gilles 496 Jul 5 13:34 /home/gilles/.XauthorityWhat's so special about Evince that it can't read ~/.Xauthority? How can I make it start?
|
Evince fails to start because it cannot read .Xauthority
|
First a clarification, X is not a window manager, it is a windowing system.
Now, the ~/.Xauthority file is simply where the identification credentials for the current user's Xsession are stored, it is the file read when the system needs to determine if you have the right to use the current X session.
You should never copy an existing one from another account, the file should always belong to the user running X and is created automatically when you start a new X session. So, just delete the one you have, and then run startx again, everything should work as normal:
$ rm ~/.Xauthority; startx
|
Recently, I switched from Ubuntu to Arch Linux. I've installed X11 as my Window System and KDE as my Desktop Environment. I've separate partition for /home, /var, / and /boot and they all mount at boot time. When I run startx, the following message gets displayed.
xauth:timeout in locking authority file /home/hello/.Xauthority
Accidently, I've deleted that file. So, I copied it from /root. I've changed it's authority using code below:
# chown hello:users ~/.Xauthority
Even after this, I'm unable to run startx unless I use root account.
|
How to run startx as non-root?
|
I believe you're getting confused by how SSH performs the proxying of the X11 connection via the tunnel it's established on the remote server side with how magic cookies typically works. From the SSH man page:
excerpt
The DISPLAY value set by ssh will point to the server machine, but with a
display number greater than zero. This is normal, and happens
because ssh creates a “proxy” X server on the server machine for forwarding
the connections over the encrypted channel.ssh will also automatically set up Xauthority data on the server machine.
For this purpose, it will generate a random authorization cookie,
store it in Xauthority on the server, and verify that any forwarded
connections carry this cookie and replace it by the real cookie when the
connection is opened. The real authentication cookie is never sent to the
server machine (and no cookies are sent in the plain).So it would seem the magic cookies being shown to you on the remote server side are not in fact the true magic cookies on the local server (your end). Remember that the DISPLAY is being set like so when you SSH into a remote server:
$ echo $DISPLAY
localhost:11.0And the magic cookies are connected by this $DISPLAY:
$ xauth list
remotey.dom.com/unix:11 MIT-MAGIC-COOKIE-1 00f505f4c5731714d30f24a956d4cb8fThe tell is that /unix:11. That's the magic cookie for the local side of the SSH connection, not your local server's X11, which would typically be :0.
.Xauthority
It's true that this file contains that magic cookies, but it's a binary file and you do typically interact with it via the xauth command. See xauth's man page for more on this.
Doing it manually
Often times you'll see this message show up if you do the following:
$ ssh -X user1@remotey
$ su - user2
$ xclockX11 connection rejected because of wrong authentication.
X connection to localhost:10.0 broken (explicit kill or server shutdown).This is because the 2nd user's .Xauthority knows nothing of the magic cookie that was passed by SSH when you logged in initially. You can generate the xauth add required while you're user1 and make use of it as user2 like so:
$ ssh -X user1@remotey
$ echo $DISPLAY
localhost:10.0Notice above that you're on display # :10.0. Now generate the xauth add required for that display #:
$ echo xauth add $(xauth list ${DISPLAY#localhost})
xauth add remotey.dom.com/unix:10 MIT-MAGIC-COOKIE-1 111ef940f6d75b4a9eb64ea3579ef67eNow become user2 and add it:
$ su - user2
$ xauth add remotey.dom.com/unix:10 MIT-MAGIC-COOKIE-1 111ef940f6d75b4a9eb64ea3579ef67e
$ xclockAnd we get the clocking showing as expected.
NOTE: You can also do things in a single command line once you've grasped what's going on with the above.
using su
$ xauth extract - ${DISPLAY#localhost} | \
su - user2 -c "xauth merge -; xclock"use sudo
$ xauth extract - ${DISPLAY#localhost} | \
sudo su - user2 -c "xauth merge -; xclock"ReferencesX Window Authorization
SSH X-11 forwarding and magic cookies
X11 Forwarding and su/sudo
|
From my local machine I ssh to a remote server along with authentication regarding X display. I know that in this process, MIT-MAGIC-COOKIES are used and the value in both server and client needs to be identical in order for the authentication process to be valid.
However, when I login to a remote server and have confirmed that X display stuff are working well (e.g. executing xclock to see if the xclock application is popped up in my local machine), when I check the value of the cookies, the value in local machine and that in the remote server seems to be different. Here's the command lines:
cookie value in remote server
chulhyun@chulhyun-Inspiron-3420:~$ ssh -X Black@$labcom
Last login: Wed Jun 25 10:02:25 2014 from Black@Black-PC ~
$ xclock ### xclock appears in local machine.Black@Black-PC ~
$ xauth list
Black-PC/unix:10 MIT-MAGIC-COOKIE-1 708f623489b1ea129a77e98287d130cacookie value in local machine
chulhyun@chulhyun-Inspiron-3420:~$ xauth list
chulhyun-Inspiron-3420/unix:0 MIT-MAGIC-COOKIE-1 5ddd2ce92004eab53ceee8a64b7b88c0As you can see the cookie value in two machines are different. Then shouldn't the X display not work?
What am I missing here?
P.S. I heard that $XAUTHORITY contains the path to the xauthority file and I've checked that path in local machine:
chulhyun@chulhyun-Inspiron-3420:~$ echo $XAUTHORITY
/var/run/gdm/auth-for-chulhyun-iZfH2u/databaseWhen I take a look into the "database" file, the contents are unreadable because the contents are composed of weird characters.
^A^@^@^Vchulhyun-Inspiron-3420^@^A0^@^RMIT-MAGIC-COOKIE-1^@^P]?,? ^D??<??? K{??could this be related to the question?update
result of xhost and $XAUTHORITY in remote server
Black@Black-PC ~
$ xhost
access control enabled, only authorized clients can connect
SI:localuser:chulhyunBlack@Black-PC ~
$ echo $XAUTHORITY*as it turns out $XAUTHORITY is not defined... is this normal?
result of xhost in local machine
chulhyun@chulhyun-Inspiron-3420:~$ xhost
access control enabled, only authorized clients can connect
SI:localuser:chulhyun
|
x11 connection established but magic-cookie value different?
|
The location of the X cookie file can be configured with the XAUTHORITY environment variable. The default is ~/.Xauthority.
Of course, the location that you pass to applications has to match the location where the cookie is stored. SLiM doesn't offer a way to add the cookie to a different file: it has ~/.Xauthority hard-coded. If you want to use a different file, patch SLiM or use a display manager that happens to have this configuration option. For example, Gdm stores X cookies under /var/run/gdm.
I think you can make .Xauthority a symbolic link, if you don't want the modifiable file to be in your home directory.
Making your home directory immutable is an exercise in futility. You're likely to encounter many other similar issues. The standard place for configuration files and state files is your home directory — that's where dot files get their name, because they start with a . so that ls won't list them by default.
|
Is it possible to change the location for .Xauthority, to something other than $HOME/.Xauthority ? AFAIU, this file is being created every time I log into LXDE, by my login manager slim.
The problem I am having is following:
I want to set my home to "immutable" using extended attributes:
chattr +i /home/martin/This way, no applications can save their files directly in /home/martin/, but they can still save files in directories located lower levels of my home, i.e. /home/martin/.config/.
At the moment, when I set my home to immutable, I cannot login to LXDE because the login manager (slim) cannot create /home/martin/.Xauthority. This happens even if the old .Xauthority exists. The login manager could just overwrite the old file with new data, but apparently this is not what it does. It creates a new file and deletes the old one. This is not allowed when /home/martin is immutable (overwriting existing file would be allowed).
Therefore, I would like to store .Xauthority somewhere else, such as .config/.Xauthority. Is this possible?
I know that xauth takes the parameter -f where file path can be specified.
UPDATE:
looking at the source code of slim, I think I might have found the place where .Xauthority is being deleted and created again:
string xauthority = pw->pw_dir;
xauthority.append("/.Xauthority");.../* reinitialize auth file */
authfile = cfg->getOption("authfile");
remove(authfile.c_str());
putenv(StrConcat("XAUTHORITY=", authfile.c_str()));
Util::add_mcookie(mcookie, ":0", cfg->getOption("xauth_path"),
authfile);How could I change the source code, so that file gets overwritten, rather than deleted/created ?
|
change location of $HOME/.Xauthority
|
The xauth cookie is stored in that temporary file (~/.xauthXXXX) which is removed when sudo returns (e.g. when the sudo xauth info command has finished).
I suggest you have a look at the source code of the pam_xauth module:
#define XAUTHTMP ".xauthXXXXXX"
...
int
pam_sm_open_session (pam_handle_t *pamh, int flags UNUSED,
int argc, const char **argv)
{
... /* Generate the environment variable
* "XAUTHORITY=<homedir>/filename". */
if (asprintf(&xauthority, "%s=%s/%s",
XAUTHENV, tpwd->pw_dir, XAUTHTMP) < 0) {
...
fd = mkstemp(xauthority + sizeof(XAUTHENV));
...
cookiefile = strdup(xauthority + sizeof(XAUTHENV)); /* Save the filename. */
if (pam_set_data(pamh, DATANAME, cookiefile, cleanup) != PAM_SUCCESS) {
...
int
pam_sm_close_session (pam_handle_t *pamh, int flags UNUSED,
int argc, const char **argv)
{
...
if (pam_get_data(pamh, DATANAME, &data) != PAM_SUCCESS)
return PAM_SUCCESS;
cookiefile = data;
...
if (unlink(cookiefile) == -1 && errno != ENOENT)
pam_syslog(pamh, LOG_WARNING, "Couldn't remove `%s': %m", cookiefile);As to pkexec, I don't think you're supposed to run X11 apps with pkexec. It's bad enough that you can run them with sudo ;-)
|
I just noticed something peculiar about how sudo handles the .Xauthority file:
sudo xauth add $(xauth list | tail -1)user@server: sudo xauth info
Authority file: /root/.xauthYZ21Nt
File new: no
File locked: no
Number of entries: 1
Changes honored: yes
Changes made: no
Current input: (argv):1user@server: sudo xauth info
Authority file: /root/.xauth3BFy5d
File new: no
File locked: no
Number of entries: 1
Changes honored: yes
Changes made: no
Current input: (argv):1user@server: sudo xauth list
server/unix:10 MIT-MAGIC-COOKIE-1 c922ab48defdf43b1092dffb86c06eeduser@server: sudo ls -la /root | grep auth
-rw-r--r-- 1 root root 0 Nov 9 14:40 .Xauthority
-rw------- 1 root root 57 Nov 9 15:23 .xauthsrxzxluser@server: pkexec xauth info
Authority file: /root/.Xauthority
File new: no
File locked: no
Number of entries: 0
Changes honored: yes
Changes made: no
Current input: (argv):1So, $XAUTHORITY value is different in every new sudo, and it points to a temporary file which disappears when sudoquits. Because of this, the last command (which uses pkexec instead of sudo and expects it to be in /root/.Xauthority) fails to see the cookie. For instance, sudo gedit runs fine, but pkexec env DISPLAY=$DISPLAY gedit fails.
Why is it done in such a complicated way, where is the data stored, and more importantly, how can I access .Xauthority data with pkexec?
|
Where is sudo hiding my root's .Xauthority data?
|
You're creating a new cookie and telling clients to use this new cookie. But the server is still using its own cookie. You can't connect to the server to retrieve the cookie without knowing the cookie.
You may be able to obtain the cookie through other means (after all, it exists in the memory of the server process). This would depend on the X server. I don't know if there's a way to do it with Xorg other than searching in the process's memory.
Depending on how the X server was invoked, the cookie may be in a file that still exists. Check the server's command line, for example
ps ww -C XorgIf there's a -auth argument, check if the file named after it still exists. For example, if you see Xorg …-auth /tmp/serverauth.abcdefgh:
xauth merge /tmp/serverauth.abcdefgh
|
I have removed for a mistake my $HOME/.Xauthority file.
I want to recreate it without restarting X11.
ATM I have start a new X11 session with this command
startx -- :1but my :0 display still don't run any X11 application.
I have tried those commands
rm ~/.Xauthority
touch ~/.Xauthority
xauth add ${HOSTNAME}/unix:0 . $(xxd -l 16 -p /dev/urandom)
xauth add ${HOSTNAME}/unix:1 . $(xxd -l 16 -p /dev/urandom)
xauth add ${HOSTNAME}/unix:10 . $(xxd -l 16 -p /dev/urandom)
xauth add ${HOSTNAME}/unix:12 . $(xxd -l 16 -p /dev/urandom)
xauth add ${HOSTNAME}/unix:13 . $(xxd -l 16 -p /dev/urandom)The command xauth list report ok
xauth list
myhost.mydomain/unix:0 MIT-MAGIC-COOKIE-1 blablabla
myhost.mydomain/unix:1 MIT-MAGIC-COOKIE-1 blablabla
myhost.mydomain/unix:10 MIT-MAGIC-COOKIE-1 blablabla
myhost.mydomain/unix:12 MIT-MAGIC-COOKIE-1 blablabla
myhost.mydomain/unix:13 MIT-MAGIC-COOKIE-1 blablablabut..
xterm -display :0
Invalid MIT-MAGIC-COOKIE-1 keyxterm: Xt error: Can't open display: :0
xeyes -display :0
Invalid MIT-MAGIC-COOKIE-1 keyError: Can't open display: :0How to generate a good Xauthority and recover my "lost" :0 display without restarting it?
Edit: I found a pseudo-solution.
If you save somewhere the old Xauthority file, or remind the right cookies the X11 display return to work, but if I don't remind the right cookies value?
|
How to generate correctly a new .Xauthority file for a display missing it, without restarting X?
|
The problem is probably that su - will clear all the environment variables except TERM, so you will lose the DISPLAY setting. Try setting DISPLAY=localhost:10.0 (for example) before the gedit.
|
I'm trying to forward my X windows, but seems to be limited to just on session?
What I'm trying to do is invoke x-applications as another user, through a sudo su -.
If I know the other user's password, than this is easily resolve with:
ssh -Y user@host
password: ********
gedit &However, if running a user which I do not have a password (weblogic, for example):
ssh –Y me@host
xauth listsudo csh (now root)
xauth add (last line of the xauth list above)
gedit &HOWEVER, I'm having trouble allowing another user to access the x display:
xauth list
su – weblogic
xauth add (last line of the xauth list above)
gedit (see if gedit launches).This fails.
I've also attempted to go direct to the to the other user via sudo:
ssh –Y me@host
xauth list
sudo su – weblogic
xauth add (last line of the xauth list above)
gedit (see if gedit launches).This too fails.
|
Forwarding X-windows through a su - session
|
There are more sophisticated versions of xhost +, namely xhost +si:localuser:root which adds only local user root to the list of allowed connections.
You need to find where to put this command so it is run on login, depending on your distribution. Look in /etc/X11/ for an existing file using xhost already. On my pi I found it in /etc/X11/Xsession.d/35x11-common_xhost-local:
if type xhost >/dev/null 2>&1; then
xhost +si:localuser:$(id -un) || :
fiOn another system it was in /etc/X11/xinit/xinitrc.d/localuser.sh.
|
I'm currently using a systemd unit file to configure a service which uses X server display.
The X server instance is launched by the user logged in (currently pi user) but the service is launched at root.
I can successfully launch the service using systemctl start test_graphic_app if I hard code the .Xauthority file location into XAUTHORITY variable from the unit file as follow
[Unit]
Description=Test Graphic App
After=multi-user.target[Service]
Type=simpleUser=root
Group=rootEnvironment="DISPLAY=:0"
Environment="XAUTHORITY=/home/pi/.Xauthority"ExecStart=/usr/bin/python3 /usr/sbin/test_graphic_app.pyKillSignal=SIGINT
SuccessExitStatus=SIGINTStandardOutput=syslog
StandardError=syslog
SyslogIdentifier=test_graphic_appRestart=on-failure[Install]
WantedBy=default.targetHowever this obviously doesn't work if I log using another user or if I run it locally on my laptop cause the user launching X is not pi
I would like to dynamically get the .Xauthority file location on the system.I've tried using sudo xauth info | grep Authority | awk '{print $3}' as follow
Environment="XAUTHORITY=$(/usr/bin/xauth info | grep Authority | awk '{print $3}')"ExecStartPre=/bin/bash -c 'export XAUTHORITY=${XAUTHORITY}'However if the command works on my laptop, it doesn't on the pi
## On laptop ##
$ sudo xauth info | grep "Authority file" | awk '{print $3}'
/run/user/1000/gdm/Xauthority## On pi ##
$ sudo xauth info | grep "Authority file" | awk '{print $3}'
xauth: file /root/.Xauthority does not exist
/root/.XauthorityI was unable find how to get the .Xauthority file location depending on the user that have launched the X server instance. Also, I don't want to allow any user to use X display doing xhost +
How can I get the location within my systemd unit?
Is there any better solution other than finding the .Xauthority location?
|
Systemd - Find .Xauthority file to use
|
There are 2 sorts of hostname entries managed by xauth, local names such as myhost/unix:0 and remote names such as remote:0. The latter are held as ip addresses, but I imagine you are referring to the local names.
The hostname part of these are not actually of any significance to X11, but can be used by the xdm tools to distinguish between several local name entries, each with different keys. To change this name simply list the entry you want, take the key at the end of the line, and provide it to the add command with your new hostname:
xauth -f ~/.newXauthority add newhostname/unix:0 . $(xauth list "$DISPLAY" |awk '{print $NF}')This assumes DISPLAY is :0, and you want the same local display number on the new machine.
|
I would like to generate a new Xauthority file using xauth with another hostname portion and write it to a different file name (as opposed to ~/.Xauthority where the xauth command typically writes to).
[Later on I want to copy this file to another machine with a different hostname. This machine is a container which binds the X socket but does not have the xauth command installed.]
UPDATE: xauth extract ~/.newXauthority $DISPLAY does almost what I want except it does not alter the hostname portion.
I did not find anything useful in xauth's man page.
|
How to replace the hostname portion with xauth (OLD: How to redirect output of xauth command?)
|
The .Xauthority lock timeout error typically is caused by problems writing to the file. Typical causes for this would include:incorrect permissions on the .Xauthority file (ownership or permissions)
over disk quota or disk full
incorrect permissions on the home directoryFrom discussion in comments, it sounds like your problem is the last of these.
Just to be sure this is the problem, run ls -ld ~ to check the permissions on your home directory. Likely, either you don't have write access, or you don't own the directory. chmod u+w ~ would fix the former, chown $USER ~ would fix the later.
|
I ask for your help since I am on linux and when I wanted to log in normally (typing my password) it kept loading indefinitely, and when I open the "console" with the key combination
(ctrl alt fn f3) and start session From there everything is fine, but when I want to start with startx it gives me the following error:
Xauth: timeout in lock authority file / home / user /. Xauthority
Try to solve it with the first two answers of (Why am I getting this message from xauth: "timeout in locking authority file /home/<user>/.Xauthority"? -authority -file-home) but it keeps giving me that error, also check the /home/user/ folder and seeing the files with the command ls -l .Xauthority didn't show me anything, it gave me the error Didn't find the file, and even typing the rm --rf Xathority command didn't give me an error, no matter how many times I ran that command, when I rebooted my computer it still didn't work like it hadn't done anything. What I can do? Thanks in advance :) and I hope I have made myself understood.
Update
Try to solve it also based on this question but it also didn't work giving me the same errors from the beginning.
I want to add that I already tried to do this:
rm -fr .Xauth- *
And also this:
rm -fr / home / user / .Xauthority
And neither way gives me an error, so I think if they are removed, but if immediately after typing those commands, I type startx, it keeps giving me the error of:
Xauth: timeout in lock authority file / home / user /. XauthoritySecond update
When I try to end the ssh session it gives me errors that are the same as some people describe in this question (https://qastack.mx/ubuntu/103889/how-do-i-restart-the-ssh-service), try to fix it with the same answers from that question but it still doesn't work where there are errors at the end of the session.
|
Xauth: timeout in lock authority file /home/user /.Xauthority
|
This is implemented by the pam_xauth.so module which you can find documented in man pam_xauth. If you look in the last line of /etc/pam.d/su you should find a line
session optional pam_xauth.sowhich runs the module when you do su - userb. In the environment, variable XAUTHORITY will be set to the temporary file with the copied cookie. This file is removed at the end of the session.
Interestingly, if usera only wants to forward their display cookie to a given set of users, they can be listed in ~usera/.xauth/export. Similarly, userb can list the users it will accept cookies from in ~userb/.xauth/import.
|
According to my own experience, su - user used to break SSH X11 authentication. There are plenty of posts on the web explaining how to use xauth list and xauth add to copy the MIT-COOKIE between sessions.
However, for some reason this is no longer necessary.
When I login using ssh -X usera@host, I see the following as usual:
-rw------- 1 usera usera 63 Jul 25 18:17 .Xauthority
When I do su - userb, the system automatically creates and uses the following:
-rw------- 1 userb userb 63 Jul 25 18:18 .xauthpNLBVw
The new .xauth file contains a copy of the MIT-COOKIE of the previous user, thus allowing me to run X11 apps. It's not necessarily a bad idea, but how is this accomplished. I've tried RHEL 5- 7 and it's the same on all those systems, even though nothing has changed that would explain this new behavior.
Any ideas? Thanks!
|
.xauth followed by random numbers
|
The X(7) overview man page (recommend reading the whole thing, by the way) tells us:The file from which Xlib extracts authorization data can be specified with the environment variable XAUTHORITY, and defaults to the file .Xauthority in the home directory.So no, XAUTHORITY is not mandatory if you have your authorization file in the usual location. It's perfectly normal for X clients to work without it. Switching users can break it because the home directory is different, and setting the environment variable helps in that case.
|
I'm using CentOS 6, with Xfce as a desktop environment and have switched to xdm from gdm as a display manager.
However, after making this change, I am observing a very strange oddity: graphical applications can run without $XAUTHORITY being defined:
$ echo $DISPLAY
:0.0
$ echo $XAUTHORITY$ zenity --error --text ".........."
$ echo $?
0And yet, when I sudo:
$ sudo -s
[sudo] password for xxxxxx:
# echo $DISPLAY
:0.0
# echo $XAUTHORITY# zenity --error --text "........."
No protocol specified(zenity:3793): Gtk-WARNING **: cannot open display: :0.0I thought both $DISPLAY and $XAUTHORITY need to be defined for a GUI to run, but this isn't happening. Does anyone have a clue as to what is going on?
EDIT:
It was suggested in the comments to inspect and use the value of DBUS_SESSION_ADDRESS_VALUE, but:
$ echo $DBUS_SESSION_BUS_ADDRESS
unix:abstract=/tmp/dbus-ypE50rEtQu,guid=7e2bc970a8ca43af3f7bb01000000255
$ echo $DISPLAY
:0.0
$ sudo -s
# export DBUS_SESSION_BUS_ADDRESS="unix:abstract=/tmp/dbus-ypE50rEtQu,guid=7e2bc970a8ca43af3f7bb01000000255"
# echo $DISPLAY
:0.0
# echo $DBUS_SESSION_BUS_ADDRESS
unix:abstract=/tmp/dbus-ypE50rEtQu,guid=7e2bc970a8ca43af3f7bb01000000255
# zenity --error --text "..........."
No protocol specified(zenity:16931): Gtk-WARNING **: cannot open display: :0.0
|
GUI running without $XAUTHORITY being defined, but not for root
|
You don't directly run user services from udev rules; instead, you should have udev tell systemd that the device wants a particular user service to run.
With a TAG+="systemd", ENV{SYSTEMD_USER_WANTS}="dslr-webcam.service" like this:
ACTION=="add", ATTR{idVendor}=="04a9", ATTR{idProduct}=="3218". TAG+="systemd", ENV{SYSTEMD_USER_WANTS}="dslr-webcam.service"
ACTION=="remove", ATTR{idVendor}=="04a9", ATTR{idProduct}=="3218", TAG+="systemd", ENV{SYSTEMD_USER_WANTS}="dslr-webcam.service"Since your dslr-webcam.service requires GUI access, it should declare itself as BindsTo=graphical-session.target and After=graphical-session.target. When declared this way, the service should get the right DISPLAY and XAUTHORITY variables automatically.
By the way, thanks for sharing your idea; it gave me inspiration to set up something very similar...
|
I am working on a systemd/udev setting that I would like to share upstream, however I can't get it to work in a non-hacky way. Essentially, I have this script as the exec of a systemd service:
ICON="somepath/dslr-camera-white.png" function on-display() {
local sdisplay=$(echo $XDG_SESSION_TYPE)
if [ "$sdisplay" == "wayland" ]; then
local display=":$(echo $WAYLAND_DISPLAY)"
else
local display=":$(ls /tmp/.X11-unix/* | sed 's#/tmp/.X11-unix/X##' | head -n 1)"
fi
local user=$(who | grep '('$display')' | awk '{print $1}' | head -n 1) local uid=$(id -u $user) sudo -u $user DISPLAY=$display DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus "$@"
} cleanup() {
on-display notify-send -i $ICON "Disconnected" "The DSLR Camera has been turned off." --app-name="DSLR Webcam"
trap - SIGTERM && kill -- -$$
} trap cleanup SIGINT SIGTERM EXIT on-display notify-send -i $ICON "Connected" "The DSLR Camera has been turned on and it is ready to use." --app-name="DSLR Webcam"
on-display yad --window-icon=$ICON --image=$ICON --no-buttons --title="DSLR Webcam" --notification --listen & output=$(v4l2-ctl --list-devices)
line=$(echo "$output" | grep "Virtual Camera")
vdevice=$(echo "$output" | sed -n "/$line/{n;s/^\t\+//p;}")
gphoto2 --stdout --capture-movie | ffmpeg -i - -vcodec rawvideo -pix_fmt yuv420p -threads 0 -f v4l2 $vdeviceThe point of the service is to be started by an udev rule when an specific gphoto2 supported camera is plugged in, therefor I have these udev rules:
ACTION=="add", ATTR{idVendor}=="04a9", ATTR{idProduct}=="3218", RUN+="systemctl start dslr-webcam.service"
ACTION=="remove", ATTR{idVendor}=="04a9", ATTR{idProduct}=="3218", RUN+="systemctl stop dslr-webcam.service"So far so "ok", because I have read on alternatives to using RUN for a systemd service, but regardless... The issue here is specifically the call to yad.
yad is a program that allows you to display dialogue boxes from the CLI, I am leveraging it for its ability to make a systrey icon, as I would like for one to show up when the camera is active.
The problem
Unlike notify-send, which probably works off some common socket, yad requires the appropriate XAUTHORITY set in order for it to work, otherwise you will get cannot open display: :0. The hacky solution in my case is to simply set it the right Xauthority, since I am using SDDM (display manager), it resides in the /tmp directory, so I can add this to the script:
XAUTHORITY=$(ls /tmp/xauth*)And then it works... But this is terrible, it makes a lot of assumptions, in fact the whole on-display function also seems like a bad idea. If I took this to a different system, it probably wouldn't work, because the proper Xauthority could be in a myriad of places, and I haven't even tried Wayland yet (I will leave that for later).
What about xauth
I thought I could somehow use xauth to retrieve the right Xauthority, but that doesn't seem to be the case... This script is a system service, so my xauth info returns Authority file: /root/.xauthWV7OfU, and running it as the right user sudo -u $user xauth info gives me Authority file: /home/myuser/.Xauthority, none of which work when given to yad. The correct XAUTHORITY is set by the display manager, so I think I could only get it from child processes of it.
I have also tried all the approaches give by this answer, but the first one would not work, as XAUTHORITY isn't actually in the system env, and the second one (aside from the mentioned pitfalls), doesn't work, it says the xauth file is at /run/sddm/xauth_KvyuHd, but trying to use it doesn't work, so it is not the same xauth file as /tmp/xauth_FzoQqz
From the same question as the previous one, this approach seems to work, but I don't know how portable it is. And still seems hacky.Run as user service
Perhaps this is the most promising one, as nothing in that script prevents it from being run as a user (it also gets rid of on-display), I did try this approach, and while if the camera was plugged-in and I ran systemctl --user start dslr-webcam.service it would work as expected (including yad), now I have a problem with the udev rule. I searched many places, including here, but I cannot find how to run a systemd user service from an udev rule, and to me that doesn't really make any sense either, how would udev know what user to use?
|
Run display dependent command in a system setting event
|
Not exactly an answer, but it probably makes more sense to run chromium under non-root:
$ docker run --rm -it --network host \
--volume ~/.Xauthority:/.Xauthority:ro \
--env DISPLAY \
alpine:3.19 \
sh -euxc 'apk add chromium shadow
useradd -m a
cp .Xauthority /home/a
chown a: /home/a/.Xauthority
exec su - a -c "DISPLAY=\"$DISPLAY\" exec chromium --no-sandbox --no-first-run"'Or better yet (I'm assuming you're running under PID 1000):
Dockerfile:
FROM alpine:3.19
RUN apk add chromium shadow && useradd -m a$ docker run --rm -it --network host \
--volume ~/.Xauthority:/home/a/.Xauthority:ro \
--env DISPLAY \
-u 1000 \
i chromium --no-sandbox --no-first-runOr using a chromium seccomp profile (created in 2016), which let's us avoid --no-sandbox:
$ curl -O https://raw.githubusercontent.com/jessfraz/dotfiles/master/etc/docker/seccomp/chrome.json
$ docker run --rm -it --network host \
--volume ~/.Xauthority:/home/a/.Xauthority:ro \
--env DISPLAY \
-u 1000 \
--security-opt seccomp=chrome.json \
i chromium --no-first-runThe seccomp profile was taken from these answers, and here's the description of how it was created.
|
$ xhost
access control enabled, only authorized clients can connectxterm works:
$ docker run --rm -it --network host \
--volume ~/.Xauthority:/root/.Xauthority:ro \
--env DISPLAY \
alpine:3.19 sh -euxc 'apk add xterm; exec xterm'chromium opens a window and seems to receive keystokes, but the window is empty (output):
$ docker run --rm -it --network host \
--volume ~/.Xauthority:/root/.Xauthority:ro \
--env DISPLAY \
alpine:3.19 sh -euxc 'apk add chromium; exec chromium --no-sandbox'If I allow local connections with xhost it works:
$ xhost +local:$ xhost
access control enabled, only authorized clients can connect
LOCAL:$ docker run --rm -it --network host \
--volume ~/.Xauthority:/root/.Xauthority:ro \
--env DISPLAY \
alpine:3.19 sh -euxc 'apk add chromium; exec chromium --no-sandbox'$ xhost -local:One could speculate here that it starts non-root processes which don't have access to /root/.Xauthority, and that's why it fails. Then under which user? So that I could provide .Xauthority to all interested parties. How do I debug this? How do I make it work?
|
Chromium doesn't start under docker without `xhost +local:`
|
Put this:
export NO_AT_BRIDGE=1 someplace where it gets run, e.g. in /etc/environment or your ~/.bashrc / ~/.bash_profile.
This workaround is suggested in this wiki page (in German) or here (in English), but I don't really understand why it's needed or what it really does, so caveat emptor.
|
When I run X apps from the command-line (e.g. leafpad; most apps), I receive the following warning on the console:
... dbind-WARNING **: ... Couldn't register with accessibility bus: Did
not receive a reply. Possible causes include: the remote application did
not send a reply, the message bus security policy blocked the reply, the
reply timeout expired, or the network connection was broken.(line broken to fit the column width.)
Why am I getting this message and what can I do about it? The apps issuing it seem to be working fine.
This appears on Ubuntu 18.04 and Devuan 3.0 Beowulf (~= Debian Buster)
|
Getting dbind-WARNING's about registering with the accessibility bus
|
As noted in the question, there have been several Linux distributions aimed at blind and visually impaired users, many of which were neglected for a long time or even abandoned.
In early 2017, Vinux announced plans to merge with Sonar, using Fedora as a basis. That was the last thing I heard about this.
TalkingArch is or was "a respin of the Arch Linux live iso modified to include speech and braille output for blind and visually impaired users". The latest version dates from 2017 and the Arch wiki points out that "TalkingArch project is dead since 2017". It was succeeded by Tarch (see below). Update 22.10.2021: The link to the Talking Arch page now redirects to the wiki page "Install Arch Linux with accessibility options".
Speakup, which is or was a set of tools for several Linux distributions, has not seen any updates for a number of years.
Oralux was based on Knoppix and included BRLTTY, Emacspeak, Yasr, Speakup and speech synthesiser for several languages. It was last updated in 2006 or 2007.
Some alternatives that are still being maintained are:Luwrain, which describes itself as "A platform for the creation of apps for the blind and partially-sighted". It has ISOs for 32-bit and 64-bit systems and bootable ISO images. Version 1.2.1 was released in May 2019.
Tarch, "the new talking arch livecd project" succeeded Talking Arch. Its latest version is 2019.06.22, released in June 2019. Update 22.10.2021: Tarch is no longer available.
There is also ADRIANE, "Audio Desktop Reference Implementation and Networking Environment", available on Knopper.net, the same website where you can find Knoppix.
Update 22.10.2021: The newest linux distro focussing on visually impaired users appears to be Accessible-Coconut, which is based on Ubuntu and was first released in the summer of 2020.Using a distribution that was specifically developed with blind users in mind is not the only option. The decisive aspect is the desktop environment and the availability of packages that blind users need. The Gnome desktop was traditionally the desktop of choice for anybody with accessibility needs. Gnome 3 was a setback with regard to accessibility, which made Mate (a continuation of Gnome 2) the better choice for many years. However, I doubt that this is still the case. For example, I can't find any dedicated accessibility page on the MATE website, whereas GNOME at least has an Accessibility Team.
|
I am looking for a Linux distro that is accessible to someone who is totally blind. I am aware of Vinux and Sonar GNU, but the former is dormant and the latter is discontinued. What is out there that both is current and also not likely to go away? This search is also satisfied by a mainstream distro like Debian or Ubuntu plus this or that application (like Orca and Lynx); just name which distro, and which app.
|
Are there any up-to-date blind-accessible Linux distros?
|
You may use a GNOME shell extension called "Block Caribou".
It claims to block caribou (the on screen keyboard) from popping up when you use a touchscreen in GNOME shell v3.26.
Edit: for later versions and if Block Caribou doesn't seem to help try the newer shell extension Block Caribou 36.
|
I am using Fedora on a computer with touch screen. When was using Fedora 26 or older, the on-screen keyboard always pops up when I am using the touch screen (like when I selected gedit window, the on-screen keyboard shows, and I have to close it manually). I found that caribou is the keyboard which annoys me, and this answer helped me (by disabling caribou).
However, after upgrading to Fedora 27 (actually I installed it from scratch), disabling caribou no longer works, and the keyboard pops up whenever I am using touch screen on gedit (and other applications). What should I do to disable it?
|
How to disable the on-screen keyboard when I use the touch screen?
|
I have the exactly same needs and, for more than a decade, Compiz has solved all these problems for me, but only when used with Xfce (not with GNOME or Unity, because it doesn't zoom the sidebar and menubars; haven't tested it with Cinnamon yet). I am currently using xubuntu 18.04, which installs Xfce by default.
Before installing Compiz, You should probably install the appropriate drivers for whatever graphics card you are using, be it Intel integrated graphics or something else.
When installing Compiz, also install compiz-plugins and compizconfig-settings-manager.
After installation:run Compiz by executing the following command in terminal (or create launcher on desktop): compiz --replace &. (Compiz is active only while the command is runing, so You should probably put it in a script which runs at startup)
open CompizConfig Settings Manager (ccsm) and enable 'Enhanced Zoom Desktop' option (under Accessibility options group) and 'Mouse Position Polling' (under Utility group)
it is possible that the mouse pointer zoom is not enabled by default, so You should open 'Enhanced Zoom Desktop' option and check 'Scale mouse pointer' option (under 'Mouse behaviour' tab)
next, You can set the zoom in/out mouse and keyboard commands ('Enhanced Zoom Desktop' -> 'Zoom In/Out'), e.g. 'Zoom in button': '<Shift><Super>Button4', 'Zoom out button': '<Shift><Super>Button5' (use Shift with Super key to prevent page scrolling while zooming in/out if pointer is inside the browser window)
to enhance smoothness of zoom area movement, adjust the 'Mouse poll interval' value under the 'Mouse position pooling' option (lower value - smoother movement).
|
I'm looking for a tool that allows to zoom in on the screen regardless of the application or program you're currently running. This tool should not only magnify the screen, but also the mouse pointer.
Background of the question is as follows: I have a visual impairment, but would like to use Linux, mainly for data security reasons. So far, I always got frustrated when I tried to use it. I failed due to the seemingly trivial problem, that any magnifier in Linux I know would only magnify a screen area, but not the mouse pointer. Even if I can do most things just using the terminal by now, it is still very annoying to do e.g. a simple internet search when you can't see your own mouse pointer.
Scaling up the pointer to the largest possible size and changing its colour to red was not sufficient for me, when I last tried it. This try is now around three years ago, when I started studying at university. I'm wondering if in the meantime someone developed something that makes Linux actually usable for me. I really like the idea of free software, but as long as it's not accessible, I'm stuck with Mac OS.
|
Is there a way to zoom in on the screen AND mouse pointer in any Linux distribution?
|
I have heard a lot of good things about Vinux, It is designed with the Visually Impaired community, And i assume that it has the best of the best with the tools you probably need.
In general you can install most of the software you want, on whatever big distro you chose to use, but the above distro has all of that built in, and even the installation is designed for that.
|
Which GNU/Linux distributions have good screen magnifier software, either freely available, or pre-installed with the OS?
Being a visually impaired nerd, I'd like to gain experience on as many platforms as possible. I've gotten accustomed to the smooth magnifying experience with the zoom functionality that comes with every Mac, so it would be nice if there were some software package available which gives me comparable results. This would greatly help me to get started with GNU/Linux.
|
Which GNU/Linux distributions have good screen magnifier software, either freely available, or preinstalled?
|
On X11 one way to achieve that is by using XKB and making the right alt key set the current latch mode as AltGr. There are a couple of ways to go about it:
Option 1
You can export your current keyboard layout to a file, change only the behavior of the right alt key (AltGr) and load it back to X, overriding the default layout:Run xkbcomp $DISPLAY current.xkb to export your current keyboard layout.Open the current.xkb file and locate the following snippet:
key <RALT> {
type= "ONE_LEVEL",
symbols[Group1]= [ ISO_Level3_Shift ]
};Change it as follows:
key <RALT> {
type= "ONE_LEVEL",
symbols[Group1]= [ ISO_Level3_Shift ],
actions[Group1]= [ LatchMods(mods=AltGr) ]
};Save the file and run xkb current.xkb $DISPLAY to apply the new layout.CaveatsThe new layout is only good for the current X session. You'll probably want to reload it automatically after you log in. If you are using a window manager, just add xkb current.xkb $DISPLAY to your .xinitrc or .xprofile. If you are using a desktop environment, it might be a little trickier because DEs usually handle keyboard layouts their own way and they can override local configurations. Be sure to check their docs, or try Option 2 below.If you use multiple keyboard languages, you'll need to repeat the steps above for each exported xkb file and somehow load them when appropriate (e.g. using a shortcut for each language).Option 2
You can create a new XKB option that enables the desired behavior for the AltGr key and then activate it along with a language layout:Create a file in /usr/share/X11/xkb/symbols named altgr with the following content:
partial alphanumeric_keys
xkb_symbols "latch" {
key <RALT> {
symbols = [ ISO_Level3_Shift ],
actions = [ LatchMods(mods=AltGr) ]
};
};Open the evdev file in /usr/share/X11/xkb/rules and locate the line ! option = symbols. Add a new line after it and insert altgr:latch = +altgr(latch). It will look like the following:
! option = symbols
altgr:latch = +altgr(latch)
...+altgr(latch) means use the latch group from the altgr file located in /usr/share/X11/xkb/symbols.Now you need to activate the new option. You can do one of the following:Run setxkbmap -layout us -variant altgr-intl -option altgr:latch to activate the new option, replacing us and altgr-intl with your language and variant. This will last for the current X session (useful for testing) and you may want to add it to .xinitrc or .xprofile so it will load automatically on login.If using systemd, run sudo localectl --no-convert set-x11-keymap us pc104 altgr-intl altgr:latch so your keyboard configuration in /etc/X11/xorg.conf.d is updated.If using a desktop environment, there might be a way to tell it to activate the option when loading the keyboard layout. I know GNOME uses dconf and you can set options for XKB in org.gnome.desktop.input-sources.xkb-options.Caveat
XKB files in /usr/share/X11/xkb aren't meant to be edited directly and might get overridden when performing system updates. The "right way" to change XKB configuration is way too complicated and I suggest you simply create a script that (re)applies the new option when needed.
|
I have found enabling sticky keys under xorg (awesome desktop manager) on Super User, which showed me that I can enable sticky keys via
xkbset sticky -twokeyThis works as expected, but in my case I'd prefer to only make a specific key (Alt Gr) be sticky instead of all modifier keys. Can this be configured? And if so: where?
|
Make specific key sticky
|
Thank to @muru,
I solved this issue by installing the caribou package
|
I use GNOME 3.36 on Arch Linux and even if control panel shows up the right option activated (see the screenshot below); none virtual keyboard is shown when needed i.e. on an input box like the search box on the upper-left corner.How can I have an onscreen-keyboard?
Do I need any external package?journalctl does not show any error/warning switching off/on the setting
|
Where is the GNOME virtual keyboard?
|
X is turning it off again. For some reason that doesn't make sense anymore, sticky keys, two keys, mouse keys, slow keys, bounce keys, and beep when LED changes expire.
Solution: xkbset exp =st in addition to the enabling command.
This changes sticky keys and two keys to be non expiring.
|
I have xkbset st -twokeys in ~/.xsession file. My process list is (mine, not system):
winbindd: domain child
/lib/systemd/systemd --user
(sd-pam)
/usr/bin/pipewire
/usr/bin/wireplumber
/usr/bin/pipewire-pulse
/usr/bin/pipewire-pulse
/usr/bin/dbus-daemon --session --address=systemd: --nofork --nopidfile --systemd-activation --syslog-only
/usr/bin/ssh-agent
ratpoison
pulseaudio
xscreensaver
xscreensaver-systemd
bash
rdesktop
ps -ef
grepxkbset st turns on stickykeys; when you press ctrl, alt, or shift it stays pressed until the next keystroke. -twokeys prevents it from being turned off by the normal keyboard disabling action of modifier pressed with normal.
How do I get stickykeys to stay on? Something is turning it off on a timer.
How often? About every 15 minutes.
This is definitely Xorg not Wayland. The window manager is ratpoison.
OS: Debian Bookworm x64
Here's an outside link to a very similar problem, but it's not caused by keyboard connection problems for me. https://forum.endeavouros.com/t/setxkbmap-keeps-resetting/17648
|
what keeps turning off stickykeys and how do I stop it?
|
The solution is to write config files into "/etc/xdg" (not "/etc").
gtk-2.0 and gtk-3.0 are directories in the same directory as configuration.nix:
environment.etc = {
"xdg/gtk-2.0".source = ./gtk-2.0;
"xdg/gtk-3.0".source = ./gtk-3.0;
};
|
Is there a way to set system-wide default GTK theme to "HighContrast" in the same manner, one can set font DPI on a system level?
Here is the snippet I use for the font DPI:
fonts = {
fontconfig = {
dpi = 160;
};
};
|
How to set a system-wide gtk theme in NixOS?
|
Just to close this question as answered: In the question you can see how to do it, it is actually possible in the visible settings application.
There only was a bug that prevented this from working correctly in GNOME 3.28 at least, and has been fixed (to be released in v3.32, I guess.).
|
When I press Shift for 8 seconds (as the upcoming dialog says, I rather feel these are 10 seconds) GNOME enables "slow keys", how they call it.
Fortunately a dialog pops up before it is finally enabled. However that cannot be quickly dismissed by navigation with the keyboard (you can only click on "Cancel", moving with the keyboard's arrow keys does not work) or by pressing ESC. I found out, however, that you can close it by holding ESC for several seconds, too.
(I would add a screenshot of that prompt here, but unfortunately this is not possible to screenshot it.)
My use case is just gaming on Linux or stuff like this, where it is perfectly fine when you hold the shift key for a longer time. As such, I do not want this dialog to pop up and dismissing it in the middle of a game is also very annoying.
As such my question is: How can I disable this prompt for enabling the keystroke delay?The help file already linked above does state there is a setting for it:Under Enable by Keyboard, select Turn on accessibility features from the keyboard to turn slow keys on and off from the keyboard. When this option is selected, you can press and hold Shift for eight seconds to enable or disable slow keys.However, the mentioned setting is already disabled in my case:GNOME 3.28.2, Fedora 28This question has been cross-posted on ask.fedoraproject.org.
|
How to disable GNOME's 8 sec. shift hotkey for activating slow keys/keystroke delay?
|
There is a direct equivalent for GNOME Web:Open the dconf editor
Navigate to org/gnome/epiphany/web/default-zoom-level
Set the value (for example 1.25)Hat tip: https://askubuntu.com/questions/207151
|
When I enable Large Text in a GNOME/Wayland desktop session it works in most applications. In GNOME Web it's a bit different:browser chrome gets bigger
some websites get bigger (e.g. https://en.wikipedia.org/wiki/Main_Page )
some websites stay the same (e.g. https://arstechnica.com )I get around this in Mozilla-based browsers by setting layout.css.devPixelsPerPx which embiggers everything (ref. https://superuser.com/a/1268867)
In GNOME Web there's a GUI tool to zoom in which has the same effect, but the effect does not persist and does not get applied to all tabs/sites. How can I make it persistent and universal?
|
How to enforce Large Text in GNOME Web?
|
It's something that could be done easily by shifting your terminal emulator's colour palette, rather than configuring bash, could you give it a try?
|
I've got a red-deficient variant of colourblindness. Red text is very difficult for me to read because it's much darker to me than for people with regular colour vision, so when it's on a black background I often can't see what it says unless I copy and paste the content to another window with a different colour scheme.
Ideally, I'd like to be able to remap the colour that the console displays as red presently to a different shade. Presently, red is shown as #c50f1f, I'd like it to be something like #fd574b instead.
Is there a way to do that in my bash_profile or similar which will impact any and all programs or scripts which output either red text or a red background?
I'm using bash in WSL, not sure if that impacts anything to do with this.
|
Can I permanently remap one colour to another in my bash_profile?
|
Solution:
apt-get install dbus-x11
...
eval $(dbus-launch --sh-syntax)
|
My docker script executes the following two commands
gsettings set org.gnome.desktop.interface toolkit-accessibility true
gsettings get org.gnome.desktop.interface toolkit-accessibilityThe first command runs (silently) but the second command returns false.
What sort of reasons would cause gsettings set org.gnome.desktop.interface toolkit-accessibility to fail? What should I be looking at?
I have installed dbus-x11 and unsuccessfully tried to start the dbus-daemon as follows, but I'm not sure I am doing the right thing.
dbus-daemon --system
dbus-daemon[2702]: Failed to start message bus: Failed to bind socket "/run/dbus/system_bus_socket": No such file or directory
|
gsettings set org.gnome.desktop.interface toolkit-accessibility true fails
|
Yes, there were attempts to create a system with its own set of characters to better describe algorithms. The most noticeable and successful was (and still is) - APL, by IBM.
IBM even created a special keyboard for writing in it.
There is a GNU APL implementation, but it looks like it is not part of any distribution and that there isn't much interest in the language.
|
I was always a bit frustrated from the lack of characters in modern computer systems such as, from what I know:A global template literal character for which the closest character today is a backtick (`)
A global quote character, for which the closest character today is a single quote mark (') or a double quote mark (")
A global escaping character for which the closest character today is backslash (\)
A global line break character, for which the closest character today is a LF or CR
Thinking about it, the entire regex language, on all its dialects, could have its own character systemI personally believe that such characters could make computing more accessible and at least intuitively would like to experiment in working this way.
I am aware that this would likely require to at least extend the QWERTY keyboard format and manufacture larger keyboards which I don't think will happen in the next 10 years, but I still want to ask on the software side:
Is there an example for a shell or computing accessibility culture aspiring a (Unix like) shell with more special characters and if so what is it?
Since the dawn of Unix and Linux, was there ever a discourse/culture about such a thing? What's worth reading? At least a name of a concept.
|
Is there an example for a shell or computing accessibility culture aspiring a shell with more special characters and if so what is it? [closed]
|
Here is a very simple example of using util-linux's unshare to put a process in a private mount namespace and give it a different view of the same filesystem its parent currently has:
{ cd /tmp #usually a safe place for this stuff
echo hey >file #some
echo there >file2 #evidence
sudo unshare -m sh -c ' #unshare requires root by default
mount -B file2 file #bind mount there over hey
cat file #show it
kill -TSTP "$$" #suspend root shell and switch back to parent
umount file #unbind there
cat file' #show it
cat file #root shell just suspended
fg #bring it back
cat file2 #round it off
}there #root shell
hey #root shell suspended
hey #root shell restored
there #roundedYou can give a process a private view of its filesystem with the unshare utility on up-to-date linux systems, though the mount namespace facility itself has been fairly mature for the entire 3.x kernel series. You can enter pre-existing namespaces of all kinds with nsenter utility from the same package, and you can find out more with man.
|
I'm trying to run ADB on a linux server with multiple users where I am not root (to play with my android emulator). The adb daemon writes its logs to the file /tmp/adb.log which unfortunately seems to be hard-coded into ADB and this situation is not going to change.
So, adb is failing to run, giving the obvious error: cannot open '/tmp/adb.log': Permission denied. This file is created by another user and /tmp has sticky bit on. If I start adb with adb nodaemon server making it write to stdout, no errors occur (I also set up its port to a unique value to avoid conflicts).
My question is: is there some way to make ADB write to another file than /tmp/adb.log? More generally, is there a way to create a sort of a process-specific symlink? I want to redirect all file accesses to /tmp/adb.log to, saying, a file ~/tmp/adb.log.
Again, I am not root on the server, so chroot, mount -o rbind and chmod are not valid options. If possible, I'd like not to modify ADB sources, but surely if there are no other solutions, I'll do that.
P.S. For the specific ADB case I can resort to running adb nodaemon server with nohup and output redirection, but the general question is still relevant.
|
Is it possible to fake a specific path for a process?
|
When Android Studio was still in Beta, I tried to get it running on FreeBSD (my preferred platform) but had nothing but issues.
I did manage to compile a debug APK but could not get a full release version (weird). I ran Android Studio under Linux Emulation but there was still issues with the Java side of things (from memory).
I even wrote a complex script for adb to help install the APKs as they would not install from the "Run" option of Android Studio. Not hard, but did speed things up a lot.
In the end I gave up and tried a heap of Linux distro (Live CDs) until I found one I was comfortable with - then installed Android Studio without issues.
Personally I still prefer FreeBSD for a lot of things but I am more than happy with a stable working environment for Android development.
Not the answer you were looking for I know, just sharing my own experience. I guess things could have changed from the Beta to now (v2.3) - but I've decided that Android Studio is updated so often (too often to be honest) that I'm not going to risk issues with FreeBSD and just run Linux.
|
I would like to know that is it possible to use Android studio in FreeBSD ?
I tried to run it but I couldn't.I installed IntelliJ from ports but there was no option to select the Android SDK.
|
Android studio on FreeBSD
|
If you install the busybox binary, it includes the nohup command (this will require root access). Busybox may be present, but the command not symlinked, in which case you would need to use busybox nohup command. If busybox is not present, then the easiest way to install is with busybox installer. After that is installed (again, with root privileges), you simply can use nohup command from adb or terminal emulator.
|
I'm trying to analyze the reason for random reboots of my phone (see here).
Therefore I wanted to record the logcat and kernel messages till the restart to see the logs even after the usb disconnects, which is probably earlier than the restart?!
So I constantly copied proc/kmsg and the logcat to files. Now this needs to NOT stop when ADB disconnects. I already tried nohup, disown, setsid, putting it in braces. Tried everything from this question.
But all these commands were not found in the shell.
So do you have another command or method for me to achieve what I want? Can I install some package / module like screen for this to work or does another (custom) kernel could help in some way?
|
How to keep running a process in Android when disconnecting adb terminal? command "nohup" not found
|
You were almost there with your first attempt. The problem is that adb unhelpfully adds a carriage return at the end of every line. You can't see it in the basic usage where the output is printed to the terminal, because a carriage return at the end of a line has no visual effect (the carriage return moves the cursor to the beginning of the current line, but then the newline moves the cursor to the beginning of the next line).
When you store the output in a variable, the carriage return is there in $af, and then adb pull treats it as part of the file name. The error message looks weird because of the carriage return in the middle, which causes the second half of the message to overwrite the first half.
Remove the carriage return before using the variable.
af=$(adb shell 'echo "$EXTERNAL_STORAGE/Pictures/Screenshots/"')
af=${af%$'\r$}
adb pull "$af" ~/or directly
adb pull "$(adb shell 'echo "$EXTERNAL_STORAGE/Pictures/Screenshots/"' | tr -d '\r')" ~/or
adb pull "$(adb shell 'echo "$EXTERNAL_STORAGE"' | tr -d '\r')/Pictures/Screenshots/" ~/Alternatively, declare the carriage return as a word separator, and leave the af variable unquoted. This only works if $af doesn't contain whitespace.
IFS+=$'\r'
adb pull $(adb shell 'echo "$EXTERNAL_STORAGE/Pictures/Screenshots/"') ~/Alternatively, create a symbolic link with a name of your choice instead of relying on the environment variable.
adb shell 'ln -s "$EXTERNAL_STORAGE" /external-storage'once and for all, then to copy files
adb pull /external-storage/Pictures/Screenshots ~/With the symlink, you can avoid the adb command line and use adbfs to mount the Android filesystem.
mkdir -p ~/mnt/android
adbfs ~/mnt/android
cp -Rp ~/mnt/android/Pictures/Screenshots ~/
|
I'm trying to use $EXTERNAL_STORAGE in the adb pull command. I noticed that the variable has its scope defined in Android only and so it would not work successfully in adb pull $EXTERNAL_STORAGE/Pictures/Screenshots/ ~/.
Of course, I can write an absolute path to fetch all the screenshots but the issue is something else.
I attempted:
af=$(adb shell echo \$EXTERNAL_STORAGE/Pictures/Screenshots/)
adb pull $af ~/which gives me the error:
' does not existstorage/sdcard0/Pictures/Screenshots/Alternatively, if I do:
af="/storage/sdcard0/Pictures/Screenshots/"
adb shell $af ~/
then the screenshots gets fetched successfully.
There is a difference in character count. For the first case where $af receives input from adb shell, the output of ${#af} and echo $af | wc -c is 39 and 40 respectively.
For the second case where a direct string is fed into $af, the output of ${#af} and echo $af | wc -c is 38 and 39 respectively.
I thought this may be a result of trailing space, so I added a space in the $af=/storage/sdcard0/Pictures/Screenshots/ " but adb pull $af ~/ still worked well.
Also, I ran echo $af | fold -w1 | wc -l and for both the cases the output is 38.
So, what's causing ADB to throw that error?If it matters, I'm using Slackware 14.1 and rooted Android 4.2.1 and 5.0.2.
|
adb pull not accepting a variable as source, gives *' does not exist..* error
|
On my gentoo system, the following udev rules are setup (in /lib64/udev/rules.d for me):
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0664", GROUP="android"
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0664", GROUP="android"
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", MODE="0664", GROUP="android"
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0664", GROUP="android"These rules give access to USB android devices (22b8 = Motorola, 0bb4 = HTC, 04e8 = Samsung and 18d1 = Google) to anyone in the android group.
The name of the group you decide to use is unimportant as long as your user is a member of that group.To address your other questions on the USB identifers, the vendor and product ids identify specific devices. You can see your identifiers using dmesg or lsusb. E.g. when I plug in my phone, dmesg reports:
[ 4573.116303] usb 4-5: New USB device found, idVendor=22b8, idProduct=2e63and lsusb reports:
Bus 004 Device 005: ID 22b8:2e63 Motorola PCSwhich tell me that my phone has a vendor id of 22b8 and product id 2e63. The udev rule:
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", MODE="0664", GROUP="android"will match this device (and all motorola phones since it is not constrained by a product id) and set permissions on the USB device for this phone to:
crw-rw-r--+ 1 root android 189, 388 May 5 19:38 /dev/bus/usb/004/005You can find your usb device to check its permissions using the usb bus and device number. lsusb reported Bus 004 Device 005 and the device path contains .../004/005. As long as you can read/write to this device you will be able to use adb and other programs that require access to the phone.
Caveat: device naming could be slightly different on your system. I'm running udev 215 and linux kernel 4.0.1.
|
I recently purchased an Android phone (my first). This is probably not relevant to the question, but it is a Micromax Canvas Hue AQ5000, running Android 4.4.2.
I want to access the phone from my computer, currently running Debian wheezy. ADB was recommended to me. I installed android-tools-adb, and after enabling Developer Options and USB Debugging, I was able to access the phone via adb shell, for example.
However, ADB does not work as user. Here is the corresponding udev file, /lib/udev/rules.d/70-android-tools-adb.rules.
# Set ACLs for console users on adb USB devices
# d001 recovery
# d002 systemACTION=="add|change", SUBSYSTEM=="usb", \
ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="d001|d002", \
TAG+="uaccess"How should I modify this file in order to give user access? The natural way seems to be to give access to a group. Along those lines, here is one suggestion,namely an answer to "Android Debug Bridge (adb) device - no permissions" which suggests
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"So, should I add GROUP="plugdev" to that file above, or is there a better way? Also what does the ATTRS{idVendor}=="18d1" part mean, and would that work for any device? Also, what does ATTRS{idProduct}=="d001|d002" mean?
I'll consider forwarding good suggestions to the Debian Bug Tracker.
|
Setting up adb for user access
|
Try
adb shell -T "ls -l" > test.logor, if it complains that error: device only supports allocating a pty:
adb shell "ls -l >/data/local/tmp/list"; adb pull /data/local/tmp/list test.logNot all the devices support the ssh inspired -t and -T options, even if your adb client program does.
This isn't Windows-specific: even on a Unix system, adb shell "ls -l" > test.log will create a file with undesirable extra carriage returns at the end of the lines.
|
I am outputting results from an android shell command to a file, with MS-windows cmd via ADB.exe.
It outputs the correct results, but I am getting an extra line between each result. It looks normal in interactive cmd (without extra lines), but when it is saved to a file the additional lines show up.
I am using Notepad++ to view the file output. When viewing all symbols, it is showing a CR(carriage return) at the end of each printed line and a CR LF for each blank line.
Is it possible to output the results to a file without the extra lines, and if so what could be causing this?
Interactively, output direct to terminal
D:\>adb shell "ls -l"
drwxr-xr-x root root 2009-12-31 19:00 acct
drwxrwx--x system cache 2020-03-12 07:14 cache
lrwxrwxrwx root root 1969-12-31 19:00 charger -> /sbin/healthd
dr-x------ root root 2009-12-31 19:00 configRedirecting to file
D:\>adb shell "ls -l" > test.log
drwxr-xr-x root root 2009-12-31 19:00 acctdrwxrwx--x system cache 2020-03-12 07:14 cachelrwxrwxrwx root root 1969-12-31 19:00 charger -> /sbin/healthddr-x------ root root 2009-12-31 19:00 config
|
Remove extra blank lines from CMD adb shell, when redirected to file
|
adb is adding a carriage-return (aka 0x0d, Ctrl-M, \r, etc) before the line-feed. Probably for ease of use with Windows software that expects lines to end with CR-LF rather than just LF.
You can see this yourself with hexdump aka hd, e.g.:
$ printf "$R" | hd
00000000 30 0d |0.|
00000002Because you only need to return a single value (the exit code). you could use printf instead of echo and redirect all of ls's output to /dev/null on the Android device to avoid printing any newlines (then adb doesn't add a CR):
R="$(adb shell 'ls /mnt/ > /dev/null 2>&1 ; printf $?')"If your android device doesn't have printf, or if you need to return one or more lines of output from a the android shell, you can use tr -d '\r' or dos2unix or sed 's/\r$//' or similar to strip the CR.
dos2unix and sed are better choices than tr here because they will only strip CRs that are immediately followed by LF, leaving alone any CRs that might be in elsewhere in a line:
$ R="$(adb shell 'ls /mnt/ > /dev/null 2>&1 ; echo $?' | dos2unix)"
$ printf "$R" | hd
00000000 30 |0|
00000001
|
For example, I want to check if a directory exists on the phone.
R=$(adb shell 'ls /mnt/; echo $?' | tail -1);$ echo $R
0$ if [ "$R" -ne 0 ]; then echo "Path doesn't exist"; else echo "Path exists"; fi
: integer expression expected
Path existsWhat's wrong with R? Ok, try it with another variable which is definitely 0.
$ x=0
$ if [ "$x" -ne 0 ]; then echo "Path doesn't exist"; else echo "Path exists"; fiPath exists$ echo "|$x|"
|0|$ echo "|$R|"
|0The second pipe isn't printed. Is there a character after 0? Try to trim:
$ R=$(adb shell 'ls /mnt/; echo $?' | tail -1 | xargs)
$ echo "|$R|"
|0I'm out of ideas.
|
How can I evaluate the result of an adb shell command?
|
ok found what was issue:
file ~/android contains some files probably store debug keys which are different after device flash/wipe - simply remove them
to be exactly:
~/.android/adbkey
|
a long time ago, i wrote a udev rule for adb with my phone (device) by setting a group. Everything was OK until some things changed recently:device rom
udev packet
adb packet now i get under user:
$ adb shell
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
error: insufficient permissions for device: verify udev rules.
See [http://developer.android.com/tools/device.html] for more information.$ adb devices -l
List of devices attached xxxxxxx no permissions (verify udev rules); see
[http://developer.android.com/tools/device.html] usb:2-1$ lsusb
// here we have the mentioned device
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub// udev rules newly added after i received an error (did'd change anything - still error i can open adb only using root)
SUBSYSTEM=="usb", ATTR{idVendor}=="1d6b", MODE="0666", GROUP="adbusers"
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", GROUP="adbusers"// this rule was added very long time ago was working perfect till now
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee7", MODE="0666", GROUP="adbusers"listed now as Bus 002 Device 007: ID 18d1:4ee7 Google Inc. // user is in adbuser group
PS. i did check a permission on device and I get:
$ ls -l /dev/bus/usb/002/001
crw-rw-r-- 1 root root 189, 128 kwi 22 13:26 /dev/bus/usb/002/001udev rules are not applied ?
ps2.
1) enabled udev deug
2) modified rules + added symlinks to track changes by udev
SUBSYSTEM=="usb", ATTR{idVendor}=="1d6b", MODE="0666", GROUP="adbusers", SYMLINK+="android%n"
SUBSYSTEM=="usb", ATTR{idVendor}=="04e8", ATTR{idProduct}=="6860", MODE="0666", GROUP="adbusers", SYMLINK+="x-android%n"
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee7", MODE="0666", GROUP="adbusers", SYMLINK+="s-android%n"after device plug
Apr 22 18:50:04 et27 systemd-udevd[304]: seq 2437 queued, 'add' 'usb'
Apr 22 18:50:04 et27 systemd-udevd[304]: Validate module index
Apr 22 18:50:04 et27 systemd-udevd[304]: Check if link configuration needs reloading.
Apr 22 18:50:04 et27 systemd-udevd[304]: seq 2437 forked new worker [1143]
Apr 22 18:50:04 et27 systemd-udevd[1143]: seq 2437 running
Apr 22 18:50:04 et27 systemd-udevd[1143]: IMPORT builtin 'usb_id' /lib/udev/rules.d/50-udev-default.rules:13
Apr 22 18:50:04 et27 systemd-udevd[304]: seq 2438 queued, 'add' 'usb'
Apr 22 18:50:04 et27 systemd-udevd[1143]: IMPORT builtin 'hwdb' /lib/udev/rules.d/50-udev-default.rules:13
Apr 22 18:50:04 et27 systemd-udevd[1143]: MODE 0664 /lib/udev/rules.d/50-udev-default.rules:41
Apr 22 18:50:04 et27 systemd-udevd[1143]: GROUP 1008 /etc/udev/rules.d/51-android.rules:4
Apr 22 18:50:04 et27 systemd-udevd[1143]: MODE 0666 /etc/udev/rules.d/51-android.rules:4
Apr 22 18:50:04 et27 systemd-udevd[1143]: LINK 's-android1' /etc/udev/rules.d/51-android.rules:4
Apr 22 18:50:04 et27 systemd-udevd[1143]: RUN '/usr/lib/virtualbox/VBoxCreateUSBNode.sh $major $minor $attr{bDeviceClass}' /etc/udev/rules.d/60-vboxdrv.rules:5
Apr 22 18:50:04 et27 systemd-udevd[1143]: PROGRAM 'mtp-probe /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/usb2/2-1 2 5' /lib/udev/rules.d/69-libmtp.rules:2283
Apr 22 18:50:04 et27 systemd-udevd[1144]: starting 'mtp-probe /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/usb2/2-1 2 5'
Apr 22 18:50:04 et27 systemd-udevd[1144]: failed to execute '/lib/udev/mtp-probe' 'mtp-probe /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/usb2/2-1 2 5': No such file or directory
Apr 22 18:50:04 et27 systemd-udevd[1143]: Process 'mtp-probe /sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/usb2/2-1 2 5' failed with exit code 2.
Apr 22 18:50:04 et27 systemd-udevd[1143]: handling device node '/dev/bus/usb/002/005', devnum=c189:132, mode=0666, uid=0, gid=1008
Apr 22 18:50:04 et27 systemd-udevd[1143]: set permissions /dev/bus/usb/002/005, 020666, uid=0, gid=1008
Apr 22 18:50:04 et27 systemd-udevd[1143]: creating symlink '/dev/char/189:132' to '../bus/usb/002/005'
Apr 22 18:50:04 et27 systemd-udevd[1143]: creating link '/dev/s-android1' to '/dev/bus/usb/002/005'
Apr 22 18:50:04 et27 systemd-udevd[1143]: creating symlink '/dev/s-android1' to 'bus/usb/002/005'
Apr 22 18:50:04 et27 systemd-udevd[1143]: created db file '/run/udev/data/c189:132' for '/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/usb2/2-1'
Apr 22 18:50:04 et27 systemd-udevd[1145]: starting '/usr/lib/virtualbox/VBoxCreateUSBNode.sh 189 132 00'
Apr 22 18:50:04 et27 systemd-udevd[1143]: Process '/usr/lib/virtualbox/VBoxCreateUSBNode.sh 189 132 00' succeeded.
Apr 22 18:50:04 et27 systemd-udevd[1143]: passed device to netlink monitor 0x562b37096e00
Apr 22 18:50:04 et27 systemd-udevd[1143]: seq 2437 processed
Apr 22 18:50:04 et27 systemd-udevd[304]: passed 308 byte device to netlink monitor 0x562b37076610
Apr 22 18:50:04 et27 systemd-udevd[1143]: seq 2438 running
Apr 22 18:50:04 et27 systemd-udevd[1143]: IMPORT builtin 'hwdb' /lib/udev/rules.d/50-udev-default.rules:15
Apr 22 18:50:04 et27 systemd-udevd[1143]: IMPORT builtin 'usb_id' /lib/udev/rules.d/60-libgphoto2-6.rules:9
Apr 22 18:50:04 et27 systemd-udevd[1143]: unable to access usb_interface device of '/sys/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/usb2/2-1/2-1:1.0'
Apr 22 18:50:04 et27 systemd-udevd[1143]: IMPORT builtin 'usb_id' returned non-zero
Apr 22 18:50:04 et27 systemd-udevd[1143]: RUN 'kmod load $env{MODALIAS}' /lib/udev/rules.d/80-drivers.rules:5
Apr 22 18:50:04 et27 systemd-udevd[1143]: created db file '/run/udev/data/+usb:2-1:1.0' for '/devices/pci0000:00/0000:00:1c.1/0000:03:00.0/usb2/2-1/2-1:1.0'
Apr 22 18:50:04 et27 systemd-udevd[1143]: Execute 'load' 'usb:v18D1p4EE7d0232dc00dsc00dp00icFFisc42ip01in00'
Apr 22 18:50:04 et27 systemd-udevd[1143]: No module matches 'usb:v18D1p4EE7d0232dc00dsc00dp00icFFisc42ip01in00'
Apr 22 18:50:04 et27 systemd-udevd[1143]: passed device to netlink monitor 0x562b37096e00
Apr 22 18:50:04 et27 systemd-udevd[1143]: seq 2438 processed
Apr 22 18:50:04 et27 systemd-udevd[304]: cleanup idle workers
Apr 22 18:50:04 et27 systemd-udevd[1143]: Unload module index
Apr 22 18:50:04 et27 systemd-udevd[1143]: Unloaded link configuration context.
Apr 22 18:50:04 et27 systemd-udevd[304]: worker [1143] exitedThe group is not applied on device I get
$ ls -al /dev/android1
lrwxrwxrwx 1 root root 15 kwi 22 18:42 /dev/android1 -> bus/usb/001/001
$ ls -al /dev/s-android1
lrwxrwxrwx 1 root root 15 kwi 22 18:50 /dev/s-android1 -> bus/usb/002/005could be an issue on string instead numeric group values ? or GROUP="" instead GROUP:="" ? if so why udev not yields on this ? notation no as symlink works with old notation so ...
string instead numeric no as its resolved proper in logs to -> 1008ok permission is set as expected - as symlinks not showing permissions
$ ls -al /dev/bus/usb/002/001
crw-rw-rw- 1 root adbusers 189, 128 kwi 22 19:04 /dev/bus/usb/002/001but still I get insufficient
|
how to debug adb insufficient permission case
|
Hypothesis: your old ~/.bashrc contained an incomplete line and the line was related to adb. Your command
echo 'HISTTIMEFORMAT="%d%m%y %T "' >> ~/.bashrcadded to the line instead of adding another line. This behavior is one of the reasons the last line should be properly terminated.
My tests indicate an incomplete line in ~/.bashrc is not ignored by Bash. You may have had an incomplete alias … line that worked. Your incomplete line might be:
alias adb='/home/user/Android/Sdk/platform-tools/adb'(maybe without the single-quotes) and after the first echo … >> ~/.bashrc it became:
alias adb='/home/user/Android/Sdk/platform-tools/adb'HISTTIMEFORMAT="%d%m%y %T "(maybe without the single-quotes). The line neither defines the exact alias you wanted, nor affects HISTTIMEFORMAT. It's a complete line though, so your second echo … >> ~/.bashrc worked as intended and created a separate line that actually affects HISTTIMEFORMAT.
In a comment you wrote:I tried removing that line from the bashrc file, but it just removed the timestamp from the history command. The adb error is still there.Removing the last line (i.e. the output of the second echo) without noticing that the previous line is contaminated (with the output of the first echo) would do exactly this. My hypothesis stands.
Check the last line of your ~/.bashrc.
|
I set up earlier this month HISTTIMEFORMAT cause I needed to see the time on some of the commands I previously used. However, I most likely messed something up with those commands, because every time I try to use adb for anything (adb kill-server eg.) I get the following error: bash: /home/user/Android/Sdk/platform-tools/adbHISTTIMEFORMAT=%d%m%y: No such file or directory. These are the commands that I used to setup HISTTIMEFORMAT:
1032 20/05/22 19:17:45 echo 'HISTTIMEFORMAT="%d%m%y %T "' >> ~/.bashrc
1033 20/05/22 19:17:46 history
1034 20/05/22 19:19:17 source ~/.bashrc
1035 20/05/22 19:19:19 history
1036 20/05/22 19:20:22 echo 'HISTTIMEFORMAT="%d/%m/%y %T "' >> ~/.bashrc
1037 20/05/22 19:20:32 source ~/.bashrcWhat exactly did I do wrong and how can I fix/revert it?
|
HISTTIMEFORMAT messed up adb
|
To keep the pipe open, don't let it close. You may do this by adding cat to the left hand side in the pipe:
{ echo "cd /storage/self/primary/Download; mkdir bobby"; cat; } | adb shellThe cat process will execute after echo, and have its standard output connected to the adb shell command, while its standard input reads from the terminal (where you may type).
As soon as cat terminates (by you pressing either Ctrl+C to interrupt, or Ctrl+D to signal end of input) the pipeline will terminate.
Note that this may not give you a full interactive shell with a prompt and command line completion or whatever other interactive features the adb shell command provides normally, but will let you send commands to the right hand side of the pipe.
This is similar to what's explained in What is meant by "keeping the pipe open"?
|
Motivation: I often open a remote shell on android devices (using adb/ Android debug bridge), and want to write scripts on my machine (not android devices, because I have multiple) to help me when i first connect into the shell.
For example, I might want to change directory into a specific folder,
echo "cd /storage/self/primary/Download; mkdir bobby" | adb shell, however the stdin in immediately closed once the code is executed, and the shell is immediately closed too. I've added mkdir bobby just to test that the line is actually executed, and it is.
For example, the shell will automatically close in 5 seconds when I run echo "cd /storage/self/primary/Download; mkdir bobby; sleep 5" | adb shell. Unfortunately, a heredoc doesn't help, because it will also close the shell once the heredoc delimiter is found.
Question: How do I keep stdin connected to terminal after piping a command into it, so that I can type into it. This is not a challenge with ssh, because you can directly pass an optional command.Apologies if this question has already asked, I wasn't sure how to phrase it.
|
Keep pipe open (stdin in connected to terminal) after pipe
|
Create a new file at /etc/udev/rules.d/50-nexus7-deb.rules:
/etc/udev/rules.d/50-nexus7-deb.rules:
# adb protocol on nexus 7 deb/razorg:
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="d001", MODE="0600", OWNER="myusername"
# fastboot protocol on nexus 7 deb/razorg
SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", ATTR{idProduct}=="4ee0", MODE="0600", OWNER="myusername"Change myusername above to be your Linux username. Simply unplug your Android device and replug to be able to access adb and fastboot as a non-root user.
|
I need to access my Nexus 7 2013 LTE (deb) over adb and fastboot, but it seems that it's required to be root to be able to run the adb server to be able to access the device due to USB rules.
How can I configure udev to allow access to this device as a non-root user for adb and fastboot?
|
How do I allow non-root access to Nexus 7 2013 LTE (deb) over adb and fastboot?
|
Following Andrew Sun's suggestion in this stackoverflow answer, I installed adbd Insecure from Google Play.
The developer according to this link
explained that the app gives root access in adb shell and allows access to system files and directories through adb push/pull, which exactly solved my problem.
After installation I was able to execute the adb pull command successfully outside adb shell.
|
I am trying to copy WeChat database file called EnMicroMsg.db so I can view it in SQLite browser.
With my Nexus 7 tablet rooted and physically connected, the usb debugging checked I ran the following commands on cmd: adb devices which confirmed that my devices is connected, adb shell to enter the shell mode, su command to gain root, `cd /data/data/com.tencent.mm/MicroMsg/ and ls to see the directories
root@flo:/data/data/com.tencent.mm/MicroMsg # lsfirst among the list is
6bb3ed9fac8c14c96ab852ea8fc570dbThen I changed to the directory 6bb3ed9fac8c14c89ab852ea8fc570db, and used ls command to list the directory content.
root@flo:/data/data/com.tencent.mm/MicroMsg/6bb3ed9fac8c14c96ab852ea8fc570db #
ls
I found it listed among the results.
CommonOneMicroMsg.db
CommonOneMicroMsg.db.ini
EnMicroMsg.db
EnMicroMsg.db.bak
EnMicroMsg.db.ini
IndexMicroMsg.db
SnsMicroMsg.dbHaving confirmed that it is located there. I exited shell mode and then tried pulling it by typing
C:\AndroidSDK\sdk\platform-tools>adb pull /data/data/com.tencent.mm/MicroMsg/6bb
3ed9fac8c14c96ab852ea8fc570db/EnMicroMsg.db
but the response I got was
remote object '/data/data/com.tencent.mm/MicroMsg/6bb3ed9fac8c14c96ab852ea8fc570
db/EnMicroMsg.db' does not existHow do I pull this file?
|
How to pull database file from physically connected android device
|
The text on your pic looks the same as the one in your script, yes. But it's a bit hard to be sure from just a pic.
But note how the text comes to your terminal when you run the script? The command substitution is supposed to capture the output, whatever gets caught by it, does not get printed. adb probably prints that message to the standard error, not standard output, so it doesn't get caught.
You could verify that with something like this:
echo "running the command substitution... (errors would print after this line)"
output=$(adb shell getprop sys.boot_completed)
echo "captured output (stdout): '$output'"Then see what comes out where.
And if that's indeed the problem, then you need to redirect the stderr to stdout in the command substitution:
if [[ "$(adb shell getprop sys.boot_completed 2>&1)" =~ "adb: no devices/emulators found" ]]; then
...
|
I was trying to execute the following shell script below
function Check_Status () { if [[ "$(adb shell getprop sys.boot_completed)" =~ "adb: no devices/emulators found" ]];
then
echo "here" else
echo "im here"
fi;
};Check_StatusI'm getting the following output, and I'm expecting to see "here" not "I'm here"Not sure what could be missing
|
unable to satisfy if condition in shell script
|
The quotes cause the command adb to be passed three arguments:shell
tcpdump
tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)It presumably then tries to run the command
tcpdump tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)without the quotes (as the shell on the machine on which you typed the command removed the quotes) on the Android machine.
You can probably do
adb shell tcpdump "'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'"which means that the adb command will be passedshell
tcpdump
'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'so that it will try to run the command
tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'on the Android machine.
The same problem would exist with, for example, ssh; the command
ssh localhost tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'gets the errors
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `tcpdump tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
|
I installed tcpdump on my Android tablet and am running commands from a root adb shell. I'm working from the tcpdump man page examples, specifically this one:To print all IPv4 HTTP packets to and from port 80, i.e. print only packets that contain data, not, for example, SYN and FIN packets and ACK-only packets.tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'If I execute the above command on my desktop (Ubuntu), it runs fine. If I try and execute it on my Android device, like this:
adb shell tcpdump 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'I get this error:
/system/bin/sh: can't create 2)) != 0): Read-only file system
/system/bin/sh: here document missing
tcpdump: syntax errorAnd the following command runs fine on the Android device:
tcpdump 'tcp port 80'It seems like the filter expression isn't being parsed properly, or something, but I'll be honest, I'm not sure how exactly it works, so I'm not sure where to start with troubleshooting. Any ideas as to what's going wrong or how to fix it?
|
tcpdump filter expression breaks via adb
|
You could just run the grep locally rather than as part of your adb expression:
$ adb shell "ip addr show wlan0" |
grep -o -P '^ *inet \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
inet 192.168.1.167The -P option there means --perl-regexp, and is necessary to support the \d escape.
You could also just use a combination of awk and cut:
$ adb shell "ip addr show wlan0 | awk '\$1 == \"inet\" {print \$2}' | cut -f1 -d/"
192.168.1.167There's a bunch of escaping there to prevent the local shell from expanding things like $1 locally.Or heck, forget traditional tools like grep and awk and do it using JSON and jq:
$ adb shell "ip -j addr show wlan0" | jq -r '.[]|select(.ifname).addr_info[]|select(.family=="inet").local'
192.168.1.167
|
I'm trying to create a one-line, platform-independent solution for finding the local IP address of a Android device with adb shell and grep (the internal grep on my android device). I have a solution that works, but something keeps bothering me.
By the way, I'm running my solution from within Powershell 7, if that makes any difference.
Here's my solution:
> adb shell "ip addr show wlan0 | grep -e 'inet[^6]'"
inet 192.168.0.19/22 brd 192.168.3.255 scope global wlan0It works, but I cannot use \d as a character class to filter, which would be preferable.
My preferred solution would show JUST the IP address and nothing else. This is the best I could do:
> adb shell "ip addr show wlan0 | grep -o '^ inet [0-9][0-9][0-9].[0-9][0-9][0-9].[0-9]'"
inet 192.168.0Android seems to ship with a limited terminal setting and uses 'toybox' to emulate the typical bash tools. They seem quite limited though, and not very much documentation is provided.
Since I can't use digit character classes or quantifiers, I can only filter for the line, and using -o is the only way to output information. So, my preferred solution is effectively impossible to do.
What can I do to extract just my local IP address with this limited toolset?
|
Using grep to extract IP through adb shell
|
I have the exact same setup as you with debian testing and installed android studio 2.3.3. It took me a while to find out that you have to set it to software graphics for the emulator phone to appear.
I still have the issue with the hello world app not appearing on the emulator and the emulator appearing as blank. I have the API set at 26. API 26 is android O which is not released yet.
As I workaround i have tried API 23.
If I try the hello world example with API 23 which is android 6 marshmallow I get the hello world example to work. It can work by click run button from the studio and clicking a device that is set to API 23. You must configure the device before launching the programme.
When you launch the emulator the word android will appear on the screen first. This means it is working.
As a test with out the hello world example setup a phone like Nexus 6P and set the API version to 23. Then run this command to see if will start and show you the android word.
~/Android/Sdk/emulator/emulator -avd Nexus_6P_API_23 -use-system-libs
Edit: I changed to using the nvidia priority drivers and now i can use the emulator with API 26 on any phone. I was using the nouveau drivers and that was producing a double free which killed the emulator display.
Try with the command line example above to see what errors you get when starting the emulator.
|
Yesterday I downloaded Android Studio for my Debian Testing system. I wanted to run a HelloWorld application (just a blank activity) but weren't able to run it. With adb I can install it without having any problems.
However, if I try to do it with Android Studio, it gets stuck on 'Installing APKs'. The same happens when I try to start it in an emulator (gets stuck on 'Waiting for target device to come online').
My device is a Samsung Galaxy S3 with LineageOS (Android 7.1.2) and root permissions. Android Studio recognizes my phone properly.
What I've already done:installed with openjdk
installed with oracle jdk
set android_home
installed all the SDK-platforms since Android 4.3 and Android
Emulator from SDK tool
installed everything from SDK tool
enabled USB-debugging
tried with MTP and PTP
tried another emulated phone
installed lib32stdc++6
restarted my computer
created new blank activity
reinstalled everything: JDK, Android SDK and Android Studio
and probably much moreI do not get any error.
Today I managed to have the emulator start by setting graphics to software but it just shows a black screen and doesn't power on.
I tried to do it until now and couldn't find a solution. I have never experienced anything close to this on other systems.
I really would like to get it running on Debian because I do not want to install Windows for this. I remember that I was able to run it on LMDE2 some time ago. So why doesn't it work on Debian Testing now? Did I forget something?
Thank you in advance.
EDIT: I am now able to use my phone to run the android application by using USB 2.0 instead of USB 3.0! Is that a normal behavior since it works with native adb? I mean, if I buy a new PC after some years which has got only USB 3.0 ports, will I not be able to use phone debugging with Android Studio or is this just an issue? It is still known since 2014 (https://stackoverflow.com/a/9548311/8292104).
However, I still cannot get the app running on an ADV. I changed graphics to software, now it shows the phone but the screen remains black and the phone won't start. What can I do to fix it?
|
Android Studio: Running application in emulator not working
|
#!/bin/bashfunction Check_Status () {while [[ "$(adb shell getprop sys.boot_completed 2>&1)" =~ "device offline" ]] || [[ "$(adb shell getprop sys.boot_completed 2>&1)" =~ "device still authorizing" ]] || [[ "$(adb shell getprop sys.boot_completed 2>&1)" =~ "no devices/emulators found" ]];
do
sleep 1
if [[ "$(adb shell getprop sys.boot_completed 2>&1)" == "" ]] || [[ "$(adb shell getprop sys.boot_completed 2>&1)" == 1 ]];
then
echo "Device is now up and running!!: '$(adb shell getprop sys.boot_completed 2>&1)'"
break
else
echo "'$(adb shell getprop sys.boot_completed 2>&1)':("
fi
done};Check_Status
|
I'm trying to execute the following shell script, where I'm trying to keep executing a command in an infinite loop and until the output is not equal to a certain substring
checkDeviceStatus=$(adb shell getprop sys.boot_completed 2>&1)function Check_Status () {while [ ! "$checkDeviceStatus" =~ "device offline" ] || [ ! "$checkDeviceStatus" =~ "device still authorizing" ]
do
if [ ! "$checkDeviceStatus" =~ "device offline" ] || [ ! "$checkDeviceStatus" =~ "device still authorizing" ];
then
echo "Device is now up and running!!: '$checkDeviceStatus'"
break
else
echo "'$checkDeviceStatus'"
fi;
done};Check_Statusbut I'm getting the following error
./shell.sh: line 6: [: =~: binary operator expected
./shell.sh: line 8: [: =~: binary operator expected
|
./shell.sh: line 6: [: =~: binary operator expected
|
Try "adb push", copy a file from your host to device to that location.
You can also verify the location(path) by using "adb shell" command. After executing "adb shell", you will get a shell prompt of your device and you can verify the location in it.
If "adb shell" or "adb psuh" doesn't work then make sure your device is connected to host properly and you gave the permission.
You can restart the adb by using "adb kill-server && adb start-server" command.
|
I recently started using the adb command line utility tool and what I'm trying to do is to extract all of the images from a folder on my android device.
I've tried the command below with no success.
adb pull /data/media/0/Pictures/Screenshots/*.png /root/DesktopI've also tried a specific image
adb pull '/data/media/0/Pictures/Screenshots/Screenshot_2017-12-15-04-51-19.png'every time i run the adb pull command i seem to get the error
adb: error: remote object '/root/data/media/0/Pictures does not exist'adb is case sensitive, so i made sure i was accurate before proceeding with the above commands
update: I have tried the adb push command but it outputs the error code
adb: error: failed to copy : Read-only file systemi failed to mention in the above example of pulling a file from my adb device, i was successful in pulling 5 wifi files, but the picture extractions remain unknown... at this point i have narrowed it down to the media folder, it will extract the data, but anything past it gets lost, file not found.
|
Dealing with adb devices
|
I'm able to extract the pids with:
$ awk 'NF == 6 {print $5}' inputfile | grep -Eo '[0-9]+'
660
660
660
660Since Android uses procfs, you can see the actual binary as a symlink in /proc/$pid/exe. But, since this is a magic (i. e. procfs) symlink that doesn't obey the normal POSIX rules, you can't use the more common methods to find its target. You can, however, use stat:
$ stat -c '%N' /proc/$$/exe
`/proc/4811/exe' -> `/system/bin/sh'
[...]
|
I have an Android command whose output is as follows:
$adb shell "head -20 /d/dma_buf/bufinfo"Dma-buf Objects:
size flags mode count exp_name buf name
00020480 00000002 00000007 00000003 ion-system-660-vendor.qti.hard dmabuf210
Attached Devices:
Total 0 devices attached09469952 00000002 00000007 00000003 ion-system-660-vendor.qti.hard dmabuf209
Attached Devices:
kgsl-3d0
Total 1 devices attached00020480 00000002 00000007 00000003 ion-system-660-vendor.qti.hard dmabuf208
Attached Devices:
Total 0 devices attached09469952 00000002 00000007 00000003 ion-system-660-vendor.qti.hard dmabuf207
Attached Devices:
kgsl-3d0
Total 1 devices attachedThere are similar entries in the file. Now what I want is to extract the pid from the exp_name field (kernel doesn't have access to the complete name that's greater than 16 bytes) and get that process's complete name from the ps output with ps pid -o comm= cf. [1] and print it along with $1 of the awk output. I am stuck at how to retrieve that. I started with the following command
$adb shell "sed -n '/dmabuf/p' /d/dma_buf/bufinfo|head -10"|awk '
BEGIN { touch temp} {echo $5 > temp; pid = $(cut -d '-' -f 3,3 temp);}
END { rm temp}
'But this yields syntax errors as:
awk: cmd. line:2: BEGIN { touch temp} {echo $5 > temp; pid = $(cut -d - -f 3,3 temp);}
awk: cmd. line:2: ^ syntax error[1] There's a problem with Android awk due to which I'm resorting to the host Linux machine's utilities.
$adb shell "awk '/dmabuf/{print}' /d/dma_buf/bufinfo|head -3"
00020480 00000002 00000007 00000003 ion-system-660-vendor.qti.hard dmabuf210
09469952 00000002 00000007 00000003 ion-system-660-vendor.qti.hard dmabuf209
00020480 00000002 00000007 00000003 ion-system-660-vendor.qti.hard dmabuf208adb shell "awk '/dmabuf/{print NF}' /d/dma_buf/bufinfo|head -3"
6
6
6So this output has 6 fields (that are tab separated). Yet when I try to print the individual fields it doesn’t do that and still prints the entire line.
$adb shell "awk '/dmabuf/{print $4}' /d/dma_buf/bufinfo|head -3"
00020480 00000002 00000007 00000003 ion-system-660-vendor.qti.hard dmabuf210
09469952 00000002 00000007 00000003 ion-system-660-vendor.qti.hard dmabuf209
00020480 00000002 00000007 00000003 ion-system-660-vendor.qti.hard dmabuf208
|
Use awk on an Android command
|
You should look at bchunk, which is specifically meant for this type of conversion. You should be able to install it with sudo yum install bchunk, but I'm only 95% sure it's in the standard repo. bchunk will create an ISO from any data tracks, and CDR for any CD audio. If you want everything in one ISO bchunk is not appropriate.
The syntax is like this,
bchunk IMAGE.bin IMAGE.cue IMAGE.isoTo create a single ISO with all the tracks in one take a look at bin2iso. bin2iso is most likely not included in your standard repo. Although RPMs do exist unofficially online. I prefer PowerISO over bin2iso, as bin2iso is fairly non-updated.
bin2iso <cuefile>You could also do the conversion using PowerISO.
It is commercial software, but the linux version is freeware. Sometimes if I have problems with the Free Software for different image conversions, I give PowerISO a go.
|
How can I convert a .cue / .bin (cdr track) image into a single .iso file?
I have
Fedora 16 (x86-64)
Linux 3.1.9-1.fc16.x86_64 #1 SMP Fri Jan 13 16:37:42 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
|
How can I convert a .cue / .bin ( with cdr tracks) image into a single .iso file?
|
Libcdio contains a collection of command-line which are CD-Text aware. Specifically, you can get CD information using the cd-info program.
For more information on using particular libcdio library functions, have a look at the online documentation.
|
What applications are available for GNU/Linux that allow read-out of CD-Text data from CDs?
Command-line programs would be preferred.
|
How can I read CD-Text information from CDs
|
cdparanoia started as a patch on a cdda2wav from 1997 and never updated the cdda2wav code. Since 2002, there is no visible activity on the project.
cdrdao was a similar short running project, founded in 1998 and no new features since at least 2004. There was never special support for bad media.
cdda2wav started in 1993 and is still actively maintained. In 2002, the "lib paranoia" was taken, made portable and enhanced over the years. Libparanoia is integrated into the maintained cdda2wav since 2002.
I recommend to use:
cdda2wav -vall paraopts=proof speed=4 cddb=0 -Band to check the statistical reports for each extracted track.
BTW: if your drive supports reading C2 pointers, use:
cdda2wav -vall paraopts=proof,c2check speed=4 cddb=0 -Bthis does a lot more than the latest cdparanoia version did. Please read
the man page to understand the error reports from libparanoia.
Note: due to a bug in cdparanoia, there are situations, where the error reports from cdparanoia miss problems that are reported by cdda2wav, so do not believe cdparanoia was more successful than cdda2wav just because it reports less problems.
|
What is currently the best way to rip scratched audio cds under Linux?
What I find complicated, is that there are several tools available but it is not clear if one tool has better error correction features than the other.
I mean, there are at least:cdparanoia
cdda2waw
cdrdao
|
How to rip scratched audio cds?
|
Thanks to @Affix's answer which gave me the right direction to head, I've figured out the solution to the problem.
The problem is definitely caused by UDEV as you've guessed. The issue is this line that is in most UDEV files related to the cdrom drive.
Example
On Fedora 19 there is the following file, /usr/lib/udev/rules.d/60-cdrom_id.rules. In this file is the following line which is co-opting the eject button for CD/DVD devices.
ENV{DISK_EJECT_REQUEST}=="?*", RUN+="cdrom_id --eject-media $devnode", GOTO="cdrom_end"You can work around the issue and disable UDEV's ability to co-opt the eject button by doing the following:Make a copy of the file 60-cdrom_id.rules
$ sudo cp /usr/lib/udev/rules.d/60-cdrom_id.rules /etc/udev/rules.d/.Edit this copied version of the file and comment out the line containing the string, DISK_EJECT_REQUEST.
$ sudoedit /etc/udev/rules.d/60-cdrom_id.rulesSave the file and the change should be noticeable immediately!The above solution fixes the problem for both eject and cdctl. So now the following commands work as expected:
lock the drive
$ eject -i on /dev/sr0
eject: CD-Drive may NOT be ejected with device button-or-$ cdctl -o1unlock the drive
$ eject -i off /dev/sr0
eject: CD-Drive may be ejected with device button-or-$ cdctl -o0
|
Up until Fedora 14 I was successfully using cdctl to enable/disable the CD/DVD eject button on my laptop (Thinkpad T410). Sadly it has stopped working now.
I've consulted the methods discussed in these 2 questions:disable cd/dvd button on linux laptop (ubuntu)
Disable the DVD eject button on a Thinkpad running LinuxNone of which have worked for me. So I turn back to cdctl to see if we can't fix what's broken with it, since it's worked for so long.
Debugging the issue
So starting with cdctl switches I notice that most things seem to work just fine.
Examples
These things work.
ejects the drive
$ cdctl -elist capabilities
$ cdctl -k
Tray close : 1
Tray open : 1
Can disable eject : 1
Selectable spin speed : 1
Is a jukebox : 0
Is multisession capable: 1
Can read the MCN (UPC) : 1
Can report media change: 1
Can play audio discs : 1
Can do a hard reset : 1
Can report drive status: 1According to that list cdctl even thinks that it can enable/disable the eject button.Can disable eject : 1So I continue on with debugging the issue.
Debugging cdctl
So I figure lets do an strace on cdctl to see if it can shed some light on what's going on.
$ strace cdctl -o1
...
brk(0) = 0x1371000
open("/dev/cdrom", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/dev/cd", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/dev/scd0", O_RDONLY|O_NONBLOCK) = -1 ENOENT (No such file or directory)
open("/dev/sr0", O_RDONLY|O_NONBLOCK) = 3
ioctl(3, CDROM_LOCKDOOR, 0x1) = 0
close(3) = 0
exit_group(0) = ?
+++ exited with 0 +++Curiously it seems like cdctl thinks it's disabling the button.
$ strace cdctl -o1
ioctl(3, CDROM_LOCKDOOR, 0x1) = 0$ strace cdctl -o0
ioctl(3, CDROM_LOCKDOOR, 0) = 0NOTE: If I understand this right, the return of a 0 means it was successful.
One thing that caught my eye here was the list of devices that cdctl is attempting to interact with. So I thought "what if I try these devices with eject"?
eject command
One of the other commands I used to use years ago was the eject command to interact with the CD/DVD device. I noticed that this command also now has a similar named switch:
$ eject --help
-i, --manualeject <on|off> toggle manual eject protection on/offExample
$ eject -i 1 /dev/sr0
eject: CD-Drive may NOT be ejected with device button$ eject -i 0 /dev/sr0
eject: CD-Drive may be ejected with device buttonSo eject too thinks that it's disabling the button, yet it isn't either. Using strace here I see the same system calls:
$ strace eject -i 1 /dev/sr0 |& grep ioctl
ioctl(3, CDROM_LOCKDOOR, 0x1) = 0$ strace eject -i 0 /dev/sr0 |& grep ioctl
ioctl(3, CDROM_LOCKDOOR, 0) = 0So now I'm wondering if UDEV or something else is potentially blocking or taking ownership of device?
Thoughts?
|
How can I disable the button of my CD/DVD drive?
|
An audio CD doesn't contain a filesystem at all. The format is defined as a particular stream of bits directly representing sounds. This is unlike DVDs, where a video DVD is a DVD with a UDF filesystem with a particular structure.
The classical CD burning suite, cdrecord, includes cdda2wav to rip an audio CD to a WAV file, and cdrecord -audio to burn a WAV file to an audio CD. Another tool for CD ripping is cdparanoia; it tries very hard to be as faithful as possible to the audio data. Many CD burning GUIs have a button or menu entry to rip, burn or copy audio CDs.
|
Is there a way to rip an audio CD to an ISO9660 file? I've tried simple things like dd in the past and it hasn't worked. I'd like to essentially have a mirror image of exactly what's on the disk, not even necessarily a folder of WAV files.
I do understand that I could rip the CD to WAV files or even FLAC files, but is there a way to just duplicate the disc to one file, so I could extract WAVs or FLACs from it later on? The idea is to be able to make a virtually identical copy of the source media.
|
Rip an audio CD 1:1
|
cdparanoia
You can get a list of CD audio tracks using the command line tool, cdparanoia.
$ cdparanoia -sQExample
$ cdparanoia -sQ
cdparanoia III release 10.2 (September 11, 2008)Table of contents (audio tracks only):
track length begin copy pre ch
===========================================================
1. 19497 [04:19.72] 0 [00:00.00] OK no 2
2. 20253 [04:30.03] 19497 [04:19.72] OK no 2
3. 29250 [06:30.00] 39750 [08:50.00] OK no 2
4. 34263 [07:36.63] 69000 [15:20.00] OK no 2
5. 28804 [06:24.04] 103263 [22:56.63] OK no 2
6. 21582 [04:47.57] 132067 [29:20.67] OK no 2
7. 33270 [07:23.45] 153649 [34:08.49] OK no 2
8. 29919 [06:38.69] 186919 [41:32.19] OK no 2
9. 29564 [06:34.14] 216838 [48:11.13] OK no 2
10. 18993 [04:13.18] 246402 [54:45.27] OK no 2
11. 35368 [07:51.43] 265395 [58:58.45] OK no 2
TOTAL 300763 [66:50.13] (audio only)You can count the number of lines that contain the string "OK" or that start with a number, for e.g. 1..
$ cdparanoia -sQ |& grep OK | wc -l
11-or-$ cdparanoia -sQ |& grep -P "^\s+\d+\." | wc -l
11cdda2wav
You can also use this command line tool, cdda2wav.
$ cdda2wav -J -D /dev/cdromExample
$ cdda2wav -J -D /dev/cdrom
Type: ROM, Vendor 'Optiarc ' Model 'DVD RW AD-7930H ' Revision '1.D1' MMC+CDDA
569344 bytes buffer memory requested, 4 buffers, 55 sectors
#icedax version 1.1.11, real time sched., soundcard, libparanoia support
AUDIOtrack pre-emphasis copy-permitted tracktype channels
1-11 no yes audio 2
Table of Contents: total tracks:11, (total time 66:50.13)
1.( 4:19.72), 2.( 4:30.03), 3.( 6:30.00), 4.( 7:36.63), 5.( 6:24.04),
6.( 4:47.57), 7.( 7:23.45), 8.( 6:38.69), 9.( 6:34.14), 10.( 4:13.18),
11.( 7:51.43)Table of Contents: starting sectors
1.( 0), 2.( 19497), 3.( 39750), 4.( 69000), 5.( 103263),
6.( 132067), 7.( 153649), 8.( 186919), 9.( 216838), 10.( 246402),
11.( 265395), lead-out( 300763)
CDINDEX discid: gteZIAUq3lgZlEmNg_HnbWL6cJc-
CDDB discid: 0x950faa0b
CD-Text: detected
CD-Extra: not detected
Album title: 'Hour of the Olympics' [from Mary Pope Osborne]
Track 1: 'Viking Ships at Sunrise Ch 3'
Track 2: 'Viking Ships at Sunrise Ch 4'
Track 3: 'Viking Ships at Sunrise Ch 5-6'
Track 4: 'Viking Ships at Sunrise Ch 7-8'
Track 5: 'Viking Ships at Sunrise Ch 9-10'
Track 6: 'Hour of the Olympics Ch 1'
Track 7: 'Hour of the Olympics Ch 2-3'
Track 8: 'Hour of the Olympics Ch 4-5'
Track 9: 'Hour of the Olympics Ch 6-8'
Track 10: 'Hour of the Olympics Ch 9'
Track 11: 'Hour of the Olympics Ch 10'
No media catalog number present.
scanning for ISRCs: 11 ...
index scan: 11...Again you can enlist the help of grep to get the number of tracks:
# traditional way to parse output
$ cdda2wav -J -D /dev/cdrom |& grep index | sed 's#.*: \(.*\)...#\1#g'
11# use grep's PCRE capability
$ cdda2wav -J -D /dev/cdrom |& grep -Po '(?<=index scan: )\d+' | tail -1
11ReferencesHowTo: Linux Rip and Encode Audio CDs
|
I'm writing a little script to analyze audio CDs. I'm specifically looking for a way to grab the track count from the CD, either from a shell-script or from Python. Is there an easy way to do this?
On an Ubuntu 12.04 derivative.
|
Reading amount of tracks from an audio CD?
|
Well, you could do it with some command line tools.
cdrecord (wodim on debian) can burn audio CDs on the fly, but it needs an *.inf files that specify track sizes etc. You can generate an inf file upfront with a dummy CD that has (say) one large audio track (74 minutes) using cdda2wav (icedax on debian).
In the live setting you record from an audio device of your choice with arecord in one xterm to a temporary file x. Use as argument of --duration the track size in seconds.
In another xterm you can start after a few seconds (to allow some buffering) cdrecord which reads the audio from a pipeline from x and uses the prepared inf file. You have to make sure that you specify speed=1 for writing.
Of course, you have to test this setup a bit (first times with cdrecord -dummy ...!) and lookup the right options.
But the manpage of cdrecord already contains an on the fly example as starting point:To copy an audio CD from a pipe (without intermediate files), first runicedax dev=1,0 -vall cddb=0 -info-onlyand then runicedax dev=1,0 -no-infofile -B -Oraw - | \
wodim dev=2,0 -v -dao -audio -useinfo -text *.infBut after you have everything figured out, you can create a script that automates all these steps.
|
There's a question over at audio.SE at the moment and I thought it may attract some answers here. I asked the user and he's happy to have it posted here to see if anyone has some ideas. Here it is verbatim:I'm working with a client who needs to minimize the time between when recording is done and when the finalized audio CD ejects from the drive.
All of the computer recording software I'm aware of will generate a file which can then be burned to an Audio CD. I know there is external hardware I could buy that would burn an analog stream directly to disc, but I'm wondering if any software exists that can achieve this with a computer's internal optical drive. Ideally for Mac, though if it only exists for Windows or Linux I would be interested to hear about it.
(Other alternatives have been explored; I would much rather not deal with optical media at all, but this is a highly specialized situation.)As to the source: "It would likely be an external USB audio interface."
If you need more info let me know.
|
Is it possible to record audio directly to a computer's optical drive?
|
The problem is the usage of mplayer cdda:// and the libcdparanoia library, because libcdparanoia has it's own caching method. This method bundles about 15 second in one request to read from the CD and that period is long enough that the CD spins down.
There are two options how you can solve this problem:mplayer which uses the library libcdio
use the option -cache from mplayer with a value that's bigger then the file size you want to readI know the second option is a bit of workaround, but when you use a package from some distribution, it's not that easy to change the library.
Also found some bug reports with the same problem from Debian and archlinux.
|
When playing audio CDs with mplayer, I always get a choppy playback. Playing audio from files, like MP3 (from any optical media, or other drives), etc. works fine. Watching video DVDs is also ok. Listening to uncompressed media that's on my hard drives, like WAV or CDR, works fine as well.
But when playing audio CDs like so:
mplayer cdda://It spins the CD, plays for a few seconds until the buffer runs out, then it spins the CD again, fills the buffer and the whole procedure repeats. I tried -nocache, that didn't help.
How do I make mplayer keep a constant buffer fill, i.e. read the CD continuously?
|
Choppy audio CD playback with mplayer
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.