How do I access the login history and wake-up reason on macOS Sierra? - macos-sierra

Can someone tell me what code do I use to access login history (successful/failed login attempt & time) and wake-up reason (why the computer is waken from sleep) on Sierra?
Thanks!

Find wake reason:
log show --predicate 'eventMessage contains "Wake reason"'
Show login history:
last | grep -i ttys
If you're on a version that predates Sierra, the log command doesn't exist. Use the following instead:
syslog | grep -i "Wake reason"

Related

How to capture iPhone app debug logs

I was researching libimobiledevice to basically capture the specific iPhone app logs. I have tried with the idevicesyslog command, but it gives me all the system logs along with my app.
I tried with idevicesyslog -d | grep com.example.Example but does not give me the info I am looking for.
I am interested in the debug logs of my app.
I know there is a way to capture it from the organizer in Xcode but I don't want to do it that way. I am planning to do it programmatically and then integrate with Appium automation script.
I was able to achieve this with idevicesyslog -d | grep '"https://ac.XYZ.COM" >& t' write to the file "t" and then clear the file and move on to the next step.
This I was able to achieve but the only issue I am facing here is that I need to update the command, like it wont write to log on real time basis when I am interacting with the device. If someone can suggest a way where it log to the file in a real time that would be great.
You can use -m option from idevicesyslog, this option is for "only print messages that contain STRING"
Example:
idevicesyslog -m "Vantage"
Hope this method is work for you :)

unable to take user input in perl

I am having a strange issue. I have written a script which is basically running a perl script in remote server using ssh.
This script is working fine but after completion of the above operation it will ask user to choose the next operation.
it is showing the options in the command prompt but while I am giving any input it is not showing in the screen even after hitting enter also it remain same.
I am not getting what is the exact issue, but it seems there is some issue with the ssh command because if I am commenting out the ssh command it is working fine.
OPERATION:
print "1: run the script in remote server \n2: Exit\n\nEnter your choice:";
my $input=<STDIN>;
chomp($input);
..........
sub run_script()
{
my $com="sshg3.exe server -q --user=user --password=pass -exec script >/dev/null";
system("$com");
goto OPERATION;
}
after completing this ssh script it is showing in screen:
1: run remote script
2: exit
Enter your choice:
but while I am giving any input it is not displaying in the screen until and unless I am exiting it using crtl C.
Please can anyone help what might be the issue here ?
One of the classic gotchas with ssh is this - that it normally runs interactively, and as such will attach STDIN by default.
This can result in STDIN being consumed by ssh rather than your script.
Try it with ssh -n instead.
You can redirect the output in command prompt if -n option is not available for you.
try this one it might work for you.
system("$com />null");
As per https://support.ssh.com/manuals/client-user/62/sshg3.html there is an option for redirecting input use --dev-null (*nix) or --null (Windows).
-n, --dev-null (Unix), -n, --null (Windows)
Redirects input from /dev/null (Unix) and from NUL (Windows).

Powershell_script resource throws error: "Your session has expired, please login again."

I am trying to use Chef to pull a file from Perforce, by calling p4 sync from a PowerShell script. As the title indicates, I am being plagued with this failure: "Your session has expired, please login again." From what I have gathered, it has something to do with the way the PowerShell script is run through Chef (using Invoke-Command?)
Here's what I have that is not working :(
powershell_script 'P4Sync' do
cwd "C:\\Program Files\\Perforce"
code <<-EOH
&".\\p4.exe" set P4PORT=server:1234
&".\\p4.exe" set P4USER=AUTOMATION_USER
set shallNotPass 'AUTOMATION_USER_PASSWORD_TICKET'
&".\\p4.exe" -d c:\\temp -P $shallNotPass client -o | &".\\p4.exe" -P $shallNotPass client -i
set rootdir '//root/scripts'
&".\\p4.exe" -P $shallNotPass sync $rootdir/script.bat
&".\\p4.exe" -P $shallNotPass sync $rootdir/script.sh
EOH
end
The other powershell_script resources that I have used (which are working) involve only PowerShell cmdlets, and not external executables.
Any suggestions would be appreciated! Also, if you care to share any other resources where I might have found this information on my own, it would also be helpful. I've spent quite a bit of time hunting the internet on this error, and haven't had much luck.
The error message is a Perforce authentication failure and suggests there's a problem with your AUTOMATION_USER_PASSWORD_TICKET. If that's actually a ticket (it should look like a hash rather than plaintext), the problem is most likely that it's expired -- by default a login ticket is only valid for 12 hours after the "p4 login" command used to acquire it.
See the documentation for "p4 login" for more on how tickets work:
http://www.perforce.com/perforce/r15.1/manuals/cmdref/p4_login.html
The easiest solution is probably to put AUTOMATION_USER in a group with an unlimited Timeout, then re-run "p4 login" to get a new ticket (which will never expire) and put that in your script.

OpenSuse - Command for Beep Sound (System Bell)

I have a source code that runs perfectly fine on Ubuntu, it does some copumtations, and at some points it beeps like this
system("beep -f 400 -l 500");
On Ubuntu I had to do
apt-get install beep
However, I migrated to OpenSuse (not my choice) and now I get this message "sh: beep: command not found", as the command and package are obviously different.
Does anybody know hot to trigger the system beep sound and define the duration and frequency? I have been able to find only one way to change the parameters
setterm -bfreq 500 -blength 500
, but no way to actually trigger the system bell (beep). The following things don't work
echo ^G
echo -e "\a"
PS - the system Bell is enabled at
Configure Desktop -> Application and System Notifications -> System Bell
and you can actually play with this
So, I did what #fvu proposed.
However, one needs to have sudo rights, to do so, otherwise (e.g. at my work-place we don't have sudo rights) there is this output message
Could not open /dev/tty0 or /dev/vc/0 for writing open: No such file or directory
In this case, you should:
sudo chmod 4755 /usr/bin/beep
as proposed here
I noticed that on my OpenSuse 12.3 system, the bell is working in xterm or gnome-terminal, but not in konsole or xfce4-terminal.
If the same applies to your system, then maybe a work-around could be creating a shell script called "beep" which calls xterm and rings the bell:
#!/bin/sh
xterm -e "echo -e '\a'; sleep 1"

How can I capture the output of remote commands then issue more remote commands?

I am running a script where it login to a server then executes the command
"passwd -n 0 -x 99999 -i -1 debug" for removing ageing of the debug user.
If the user debug is not present then I want to create the user debug, change the password it, and then execute the above command for ageing.
How can I do?
Regards,
vasistha
From perlfunc(1):
system LIST
[...]
The return value is the exit status of the program as returned
by the "wait" call. To get the actual exit value, shift right
by eight (see below).
Therefore:
my $ret = system(qw/passwd -n 0 -x 99999 -i -1 debug/);
if ($ret != 0) {
# failure handling code here
}
Use puppet.
If you really insist on doing it manually, use getent passwd debug to check whether the user exists:
if [ $(getent passwd debug | wc -l ) = 0 ]; then
adduser debug
fi
I suggest using something like Expect. It handles the interactivity for you. You can log in to the server, execute commands, inspect the output, send more input, and so on. If you are doing lots of remote server administration, it's a very handy tool to know. There's even an article about it in The Perl Review Issue 4.2 (Spring 2008)