Expansion not working properly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expansion not working properly
# 8  
Old 09-29-2015
Quote:
Originally Posted by Corona688
grep did not match any "UNF\1122" in the ps output because none of the ps output contained "UNF\1122".

I am not sure what \1122 is supposed to be, but it's some unicode character you may not have noticed because it's probably unprintable in your terminal.

Make sure that it's not actually in your user name:

Code:
awk -v U="$UID" -F":" '$3 == U { print $1 }' /etc/passwd | hexdump -C

This isn't Cygwin, is it?
With this it matched the "U" "N" "F" "\" "1" "2" "2" "2". As individual characters. I have my color on in grep.

Code:
$ ps -ef | grep "[$USER]"

These are NOT "\1122" trailing characters. My username is "UNF\1122". Don't ask me why. That is what the administrator felt like doing.

That awk command is not giving any output.

I am using Ubuntu.

Quote:
Originally Posted by Aia
You said you were in an Ubuntu box. The env USER should be set to just the name of the account you're logged in. Somewhat, it has been set to that "UNF\1122", unless that that's the name of the account.

Check what's the user name:
Code:
grep UNF /etc/passwd | od -bc

Log out and log in again and check once more for env
"UNF\1122" IS my username.

The way the admin setup the accounts is weird. My username is not in /etc/passwd file.
# 9  
Old 09-29-2015
Quote:
Originally Posted by cokedude
"UNF\1122" IS my username.

The way the admin setup the accounts is weird. My username is not in /etc/passwd file.
That's a bit short-sighted from the part of who decided to have that scheme of username. The `\' is special to the shell. It is used as the escape character. That's why the original command would not work:
Quote:
Code:
ipcs -m | grep $USER | awk '{printf "%s ",$2}'

If USER="UNF\\\\1122" or USER='UNF\\1122', then that command might work

Or maybe

Code:
ipcs -m | awk -v user="${USER%\\\\*}" '$0 ~ user {printf "%s ", $2}'


Last edited by Aia; 09-29-2015 at 09:53 PM..
# 10  
Old 09-30-2015
What be the output of
Code:
 /bin/ps -ouser

?
# 11  
Old 09-30-2015
Quote:
Originally Posted by cokedude
With this it matched the "U" "N" "F" "\" "1" "2" "2" "2". As individual characters. I have my color on in grep.
Really?
Quote:
The way the admin setup the accounts is weird. My username is not in /etc/passwd file.
That's the file awk was looking at. It must be there.

I'm surprised he was able to put that in a username, really. From man useradd:

Code:
       Usernames must start with a lower case letter or an underscore,
       followed by lower case letters, digits, underscores, or dashes. They
       can end with a dollar sign. In regular expression terms:
       [a-z_][a-z0-9_-]*[$]?

# 12  
Old 09-30-2015
Quote:
Originally Posted by Corona688
Really?

That's the file awk was looking at. It must be there.

I'm surprised he was able to put that in a username, really. From man useradd:

Code:
       Usernames must start with a lower case letter or an underscore,
       followed by lower case letters, digits, underscores, or dashes. They
       can end with a dollar sign. In regular expression terms:
       [a-z_][a-z0-9_-]*[$]?

This is probably a user created from a LDAP, therefore it will not be a local user in /etc/passwd.
# 13  
Old 10-01-2015
Quote:
Originally Posted by Aia
This is probably a user created from a LDAP, therefore it will not be a local user in /etc/passwd.
Except he told me the command I gave him, which worked, printed a user from /etc/password Smilie
# 14  
Old 10-01-2015
Quote:
Originally Posted by Corona688
Except he told me the command I gave him, which worked, printed a user from /etc/password Smilie
Are you talking about this?

Code:
awk -v U="$UID" -F":" '$3 == U { print $1 }' /etc/passwd | hexdump -C

This is what I said? Sorry if I was confusing.

Quote:
That awk command is not giving any output.
Quote:
Originally Posted by Aia
That's a bit short-sighted from the part of who decided to have that scheme of username. The `\' is special to the shell. It is used as the escape character. That's why the original command would not work:

If USER="UNF\\\\1122" or USER='UNF\\1122', then that command might work

Or maybe

Code:
ipcs -m | awk -v user="${USER%\\\\*}" '$0 ~ user {printf "%s ", $2}'

These don't seem to be working Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join not working properly

I want to join two files , with file 1 col 3 and file 2 col 1 as key. The join command is erratic for some reason. File 2 is a master file having all the names, and file 1 has some values. I want to add the names from fil2 in file 1. If I use the original master file, some output is missing. ... (16 Replies)
Discussion started by: ritakadm
16 Replies

2. Shell Programming and Scripting

Why is sort not working properly here ?

Platform: RHEL 5.4 In the below text file I have strings like following. $ cat /tmp/mytextfile.txt DISK1 DISK10 DISK101 DISK102 DISK103 DISK104 DISK105 DISK106 DISK107 DISK108 DISK109 DISK110 DISK111 DISK112 DISK113 DISK114 (8 Replies)
Discussion started by: kraljic
8 Replies

3. Shell Programming and Scripting

Parameter expansion not working for all strings...

I'm trying to write a script that parses my music collection and hard link some filenames that my media player doesn't like to other names. To do this I need to extract the name and remove alla non ASCII characters from that and do a cp -l with the result. Problem is this: 22:16:58 $... (8 Replies)
Discussion started by: refuser
8 Replies

4. Shell Programming and Scripting

uuencode is not working properly

Hello Everyone, I'm very new to the shell script. I'm trying to send multiple attachments in unix using uuencode command. Total I have 3 text files which should be send in mail. but I'm getting 6 files and 3 files with subject as file name. And the content is ` end I'm working... (6 Replies)
Discussion started by: narikivar
6 Replies

5. Red Hat

sudo is not working properly

This is the first time for using sudo for me. # visudo ## Allows people in group admin to run all commands %admin ALL=(ALL) ALL # groupadd admin # useradd temp # usermod -a -G admin temp # id temp uid=506(temp) gid=506(temp) groups=506(temp),507(admin) # #sudo... (5 Replies)
Discussion started by: getrue
5 Replies

6. UNIX for Advanced & Expert Users

Sendmail is not working properly

Hi All, Can any one help me to solve the issue. The Issue is, i have started the sendmail service on my RHEL 4 update 6 box, I am able to send the mail from my box to almost all of the Email Id's except few. Exampe, test mail. . Output is :the message is sent. now if I send the... (2 Replies)
Discussion started by: akhtar.bhat
2 Replies

7. Shell Programming and Scripting

\n not working properly

Hi all, I'm trying to generate a series of txt files starting from a plain csv file part of my code: #!/bin/ksh INSTALLDIR=/Users/ME/Installdir CSV=CSV.csv TMP=/tmp/$(basename $0).txt tr -s "\r" "\n" < /$INSTALLDIR/$CSV > $TMP function Makefiles { printf '%24s:%30s\n' "sometext"... (1 Reply)
Discussion started by: Jive Spector
1 Replies

8. UNIX for Dummies Questions & Answers

Telnet is not working properly

telnet at my system is behaving stange. Some times I am able to telnet to other machines but sometimes it stop doing that. Then i have to reboot the machine and most of the time (not 100%) it works. SImilar is the case with SSH. Sometime it works , some time it don't. i am new to Unix and I do not... (1 Reply)
Discussion started by: deepak_pathania
1 Replies

9. Shell Programming and Scripting

Basic variable expansion not working...

#!/usr/bin/bash if then echo "Not valid arguments entered. Just username should be entered." else USER_NAME=$1 FILE_NAME=$USER_NAME.info UNN=STUDIN\\\\$1 echo $UNN last STUDIN\\\\$1 last UNN If I type `last STUDIN\\eip060` it works but if I try to expand it with variable it is... (5 Replies)
Discussion started by: Zammy_bg
5 Replies

10. Programming

y is this not working properly?

#include <stdio.h> #include <sys/types.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> struct stat s; main() { char c; if (fork()==0) { system("clear"); do { printf("myAI\\>§ "); scanf("%s",c); if(stat(c,&s)>-1) {... (3 Replies)
Discussion started by: C|[anti-trust]
3 Replies
Login or Register to Ask a Question