I have this linux command:
candump -l -e -x -s 0 -n 10 any,0~0,#FFFFFFFF 2> /dev/null > /tmp/can.log &
It works correctly when I run it directly in shell.
I want to add it in my script with this method:
#!/bin/sh
# I tried this 2 syntax
# MYVAR="candump -l -e -x -s 0 -n 10 any,0~0,#FFFFFFFF 2> /dev/null > /tmp/can.log &"
MYVAR='candump -l -e -x -s 0 -n 10 any,0~0,#FFFFFFFF 2> /dev/null > /tmp/can.log &'
$MYVAR
When I execute my script I get this error:
SIOCGIFINDEX: No such device
I have tested these script and it works:
#!/bin/sh
MYVAR='ls -l'
$MYVAR
Result:
total 8
drwxr-xr-x 2 root root 0 Nov 5 2015 bin
drwxr-xr-x 2 root root 0 Oct 22 2015 boot
drwxr-xr-x 5 root root 13460 Jan 1 00:00 dev
drwxr-xr-x 8 root root 0 Nov 5 2015 etc
drwxr-xr-x 3 root root 0 Nov 5 2015 home
-rwsr-xr-x 1 root root 258 Nov 5 2015 init
drwxr-xr-x 3 root root 0 Nov 5 2015 lib
drwxr-xr-x 3 root root 0 Nov 5 2015 media
drwxr-xr-x 3 root root 0 Nov 5 2015 mnt
dr-xr-xr-x 67 root root 0 Jan 1 00:00 proc
drwx------ 2 root root 0 Oct 22 2015 root
drwxr-xr-x 4 root root 0 Jan 1 00:00 run
drwxr-xr-x 2 root root 0 Nov 5 2015 sbin
dr-xr-xr-x 14 root root 0 Jan 1 00:00 sys
-rwxr-xr-x 1 root root 33 Jan 1 00:04 test
drwxrwxrwt 2 root root 0 Jan 1 00:00 tmp
drwxr-xr-x 9 root root 0 Oct 22 2015 usr
drwxr-xr-x 7 root root 0 Oct 22 2015 var
I can't see the error, can you explain me the error?
Better (and safer) to use a shell function rather that a variable:
#!/bin/sh
myfunc() {
candump -l -e -x -s 0 -n 10 any,0~0,#FFFFFFFF 2>/dev/null >/tmp/can.log &
}
# call it
myfunc
Related
MWE
I have a GitHub Actions workflow that recently stopped working without me making changes. The error:
==> ERROR: /etc/makepkg.conf not found.
Aborting...
This is from running # sudo -Eu builder makepkg --printsrcinfo.
Source
Logs
The order of the logs seem to be wrong but it is correct in an earlier log (possibly due to ls -l having a large output).
The source of this error seems to be libmakepkg/util/config.sh.in:
# Source the config file; fail if it is not found
if [[ -r $MAKEPKG_CONF ]]; then
source_safe "$MAKEPKG_CONF"
else
error "$(gettext "%s not found.")" "$MAKEPKG_CONF"
plainerr "$(gettext "Aborting...")"
exit $E_CONFIG_ERROR
fi
I added the following to my entrypoint script:
echo "Writing SRCINFO..."
# Debug
echo "---"
ls -l /
echo "---"
ls -l /etc
echo "---"
sudo -Eu builder cat /etc/makepkg.conf
echo "---"
sudo -Eu builder /bin/bash -c "[[ -r "/etc/makepkg.conf" ]] && echo 1 || echo 0"
echo "---"
sudo -Eu builder makepkg --printsrcinfo > .SRCINFO
The builder user is created in build.sh:
useradd builder -m
echo "builder ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
I got:
Setting permissions...
Writing SRCINFO...
---
total 52
lrwxrwxrwx 1 root root 7 Feb 1 19:19 bin -> usr/bin
drwxr-xr-x 2 root root 4096 Jan 19 01:32 boot
drwxr-xr-x 5 root root 340 Feb 7 11:58 dev
-rwxr-xr-x 1 root root 836 Feb 7 11:57 entrypoint.sh
drwxr-xr-x 1 root root 4096 Feb 7 11:58 etc
drwxr-xr-x 6 root root 4096 Feb 7 11:58 github
drwxr-xr-x 1 root root 4096 Feb 7 11:57 home
lrwxrwxrwx 1 root root 7 Feb 1 19:19 lib -> usr/lib
lrwxrwxrwx 1 root root 7 Feb 1 19:19 lib64 -> usr/lib
drwxr-xr-x 2 root root 4096 Jan 19 01:32 mnt
drwxr-xr-x 2 root root 4096 Jan 19 01:32 opt
dr-xr-xr-x 159 root root 0 Feb 7 11:58 proc
drwxr-x--- 2 root root 4096 Jan 19 01:32 root
drwxr-xr-x 1 root root 4096 Feb 7 11:58 run
lrwxrwxrwx 1 root root 7 Feb 1 19:19 sbin -> usr/bin
drwxr-xr-x 4 root root 4096 Feb 1 19:19 srv
dr-xr-xr-x 12 root root 0 Feb 7 11:58 sys
drwxrwxrwt 2 root root 4096 Jan 19 01:32 tmp
drwxr-xr-x 1 root root 4096 Feb 7 11:57 usr
drwxr-xr-x 1 root root 4096 Feb 1 19:19 var
---
total 640
-rw-r--r-- 1 root root 0 Jan 19 01:32 arch-release
drwxr-xr-x 3 root root 4096 Feb 1 19:19 audit
-rw-r--r-- 1 root root 28 Dec 20 18:44 bash.bash_logout
-rw-r--r-- 1 root root 618 Dec 20 18:44 bash.bashrc
-rw-r--r-- 1 root root 447 Dec 2 16:02 bindresvport.blacklist
drwxr-xr-x 2 root root 4096 Dec 16 14:38 binfmt.d
drwxr-xr-x 4 root root 4096 Feb 1 19:19 ca-certificates
-rw------- 1 root root 722 Jan 19 01:32 crypttab
drwxr-xr-x 2 root root 4096 Feb 1 19:19 default
drwxr-xr-x 2 root root 4096 Jan 7 19:51 depmod.d
-rw-r--r-- 1 root root 685 Jan 31 20:31 e2scrub.conf
-rw-r--r-- 1 root root 97 Jan 13 22:50 environment
-rw-r--r-- 1 root root 1362 Jan 20 21:31 ethertypes
-rw-r--r-- 1 root root 126 Jan 19 01:32 fstab
-rw-r--r-- 1 root root 2584 Feb 6 00:09 gai.conf
-rw-r--r-- 1 root root 626 Feb 7 11:57 group
-rw-r--r-- 1 root root 610 Jan 31 00:20 group-
-rw------- 1 root root 558 Feb 7 11:57 gshadow
-rw------- 1 root root 546 Jan 31 00:20 gshadow-
-rw-r--r-- 1 root root 73 Jan 19 01:32 host.conf
-rw-r--r-- 1 root root 13 Feb 7 11:58 hostname
-rw-r--r-- 1 root root 174 Feb 7 11:58 hosts
-rw-r--r-- 1 root root 714 Dec 8 17:48 inputrc
drwxr-xr-x 2 root root 4096 Feb 1 19:19 iproute2
drwxr-xr-x 2 root root 4096 Feb 1 19:19 iptables
-rw-r--r-- 1 root root 20 Jan 19 01:32 issue
drwxr-xr-x 3 root root 4096 Feb 1 19:19 kernel
drwxr-xr-x 2 root root 4096 Jul 7 2020 keyutils
-rw-r--r-- 1 root root 369 Jan 14 00:32 krb5.conf
-rw-r--r-- 1 root root 18096 Feb 7 11:57 ld.so.cache
-rw-r--r-- 1 root root 117 Jan 19 01:32 ld.so.conf
drwxr-xr-x 1 root root 4096 Feb 7 11:57 ld.so.conf.d
-rw-r----- 1 root root 191 Jan 13 22:33 libaudit.conf
drwxr-xr-x 2 root root 4096 Feb 1 19:19 libnl
-rw-r--r-- 1 root root 17 Jan 31 00:19 locale.conf
-rw-r--r-- 1 root root 18 Jan 31 00:19 locale.gen
-rw-r--r-- 1 root root 9984 Feb 6 00:09 locale.gen.pacnew
-rw-r--r-- 1 root root 5645 Sep 7 13:42 login.defs
-rw-r--r-- 1 root root 5792 Jul 1 2020 makepkg.conf
-rw-r--r-- 1 root root 812 Jan 31 20:31 mke2fs.conf
drwxr-xr-x 2 root root 4096 Jan 7 19:51 modprobe.d
drwxr-xr-x 2 root root 4096 Dec 16 14:38 modules-load.d
-rw-r--r-- 1 root root 0 Jan 19 01:32 motd
lrwxrwxrwx 1 root root 12 Feb 7 11:58 mtab -> /proc/mounts
-rw-r--r-- 1 root root 767 Dec 2 16:02 netconfig
-rw-r--r-- 1 root root 2717 Feb 6 00:09 nscd.conf
-rw-r--r-- 1 root root 328 Jan 19 01:32 nsswitch.conf
drwxr-xr-x 1 root root 4096 Feb 7 11:57 openldap
lrwxrwxrwx 1 root root 19 Feb 1 19:19 os-release -> /usr/lib/os-release
-rw-r--r-- 1 root root 3264 Feb 7 11:57 pacman.conf
-rw-r--r-- 1 root root 2883 Jul 1 2020 pacman.conf.pacnew
drwxr-xr-x 1 root root 4096 Feb 7 11:57 pacman.d
drwxr-xr-x 1 root root 4096 Feb 7 11:57 pam.d
-rw-r--r-- 1 root root 744 Feb 7 11:57 passwd
-rw-r--r-- 1 root root 699 Jan 31 00:20 passwd-
drwxr-xr-x 2 root root 4096 Feb 1 19:19 pkcs11
-rw-r--r-- 1 root root 1020 Jan 19 01:32 profile
drwxr-xr-x 1 root root 4096 Feb 7 11:57 profile.d
-rw-r--r-- 1 root root 3171 Jan 3 17:14 protocols
-rw-r--r-- 1 root root 1814 Jul 7 2020 request-key.conf
drwxr-xr-x 2 root root 4096 Jul 7 2020 request-key.d
-rw-r--r-- 1 root root 649 Feb 7 11:58 resolv.conf
-rw-r--r-- 1 root root 1634 Feb 6 00:09 rpc
-rw-r--r-- 1 root root 139 Jan 19 01:32 securetty
drwxr-xr-x 2 root root 4096 Feb 1 19:19 security
-rw-r--r-- 1 root root 297708 Jan 3 17:14 services
-rw------- 1 root root 375 Feb 7 11:57 shadow
-rw------- 1 root root 346 Jan 31 00:20 shadow-
-rw-r--r-- 1 root root 83 Jan 19 01:32 shells
drwxr-xr-x 2 root root 4096 Feb 1 19:19 skel
drwxr-xr-x 5 root root 4096 Feb 1 19:19 ssl
-rw-r--r-- 1 root root 3975 Jan 26 18:34 sudo.conf
-r--r----- 1 root root 3160 Feb 7 11:57 sudoers
drwxr-x--- 2 root root 4096 Jan 26 18:34 sudoers.d
-rw-r--r-- 1 root root 6169 Jan 26 18:34 sudo_logsrvd.conf
drwxr-xr-x 2 root root 4096 Dec 16 14:38 sysctl.d
drwxr-xr-x 1 root root 4096 Feb 7 11:57 systemd
drwxr-xr-x 2 root root 4096 Dec 16 14:38 tmpfiles.d
drwxr-xr-x 1 root root 4096 Feb 7 11:57 udev
drwxr-xr-x 1 root root 4096 Feb 1 19:19 X11
-rw-r--r-- 1 root root 642 May 7 2020 xattr.conf
drwxr-xr-x 1 root root 4096 Feb 1 19:19 xdg
drwxr-xr-x 2 root root 4096 Feb 1 19:19 xinetd.d
---
#!/hint/bash
#
# /etc/makepkg.conf
#
...
SRCEXT='.src.tar.gz'
---
0
---
==> ERROR: /etc/makepkg.conf not found.
Aborting...
(The contents of /etc/makepkg.conf was concatenated.)
I also accidentally did [[ -r "/etc/makepkg.conf" ]] && echo 1 || echo 0 (as root) and I also got 0.
How is it possible that a file is not readable yet I can cat it? I also tried running the exact same commands in a local container and couldn't reproduce this issue, but this has happened every GitHub Actions run since it started.
This makes me think the Actions setup is causing an issue, but nothing seems odd there:
/usr/bin/docker build -t 442333:35a065f0b9f356b32f2852ba2f6b7296 -f "/home/runner/work/visual-studio-code-insiders-arch/visual-studio-code-insiders-arch/./.github/actions/pkg/Dockerfile" "/home/runner/work/visual-studio-code-insiders-arch/visual-studio-code-insiders-arch/.github/actions/pkg"
/usr/bin/docker run --name a065f0b9f356b32f2852ba2f6b7296_baf94b --label 442333 --workdir /github/workspace --rm -e pythonLocation -e LD_LIBRARY_PATH -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e RUNNER_OS -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/visual-studio-code-insiders-arch/visual-studio-code-insiders-arch":"/github/workspace" 442333:35a065f0b9f356b32f2852ba2f6b7296
Thanks for sharing this. I have precisely the same problems.
I added the following in my Dockerfile
RUN sed -i 's/\tif \[\[ -r $MAKEPKG_CONF \]\]; then/\tif \[\[ -f $MAKEPKG_CONF \]\]; then/' /usr/share/makepkg/util/config.sh
which replaces the check for read permission (-r) for the check whether the file exists and is a regular file (-f).
now my github action gets over this particular location, but fails with the next check:
==> ERROR: You do not have write permission for the directory $BUILDDIR (/tmp/aurutils).
Aborting...
This is not a solution and does not answer what's the underlying issue, but I hope it helps anyways.
This issue is caused by using glibc >= 2.33 on the container and an outdated version of the Docker engine on the host.
You can fix it by patching glibc in your container:
patched_glibc=glibc-linux4-2.33-4-x86_64.pkg.tar.zst
curl -LO https://repo.archlinuxcn.org/x86_64/$patched_glibc
bsdtar -C / -xvf $patched_glibc
Thanks to lxqt-panel for the workaround.
I have lots of old log files in a directory, with apps logs generated every month to this directory. I want to use a script to remove only the last month old logs.
This is my file logsDir , these files are 0kb, i have created for question understanding
[root#dasari9 logDir]# ls -ltr
total 136
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram9.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram8.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram7.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram6.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram69.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram68.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram67.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram66.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram5.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram59.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram58.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram57.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram56.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram4.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram49.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram48.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram47.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram46.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram3.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram39.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram38.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram37.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram36.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram2.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram29.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram28.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram27.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram26.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram1.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram19.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram18.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram17.logs
-rw-r--r-- 1 root root 0 Mar 20 12:22 ram16.logs
This is my logs.sh:
#!/bin/bash
Jan=Dec Feb=Jan Mar=Feb Apr=Mar May=Apr Jun=May Jul=Jun Aug=Jul Sep=Aug Oct=Sep Nov=Oct Dev=Nov
DIR=/logDir
cd $DIR
if [ $DIR -eq $PWD ]; then
PWD=$(pwd)
cmd=$(date |awk '{print $2}')
dat=$(ls -ltr |grep $cmd |awk '{print $9}')
rm -rf $dat
else
echo " enterend in the wrong dir"
fi
but it's failing to get that variable value Apr=Mar
This is the output, I'm trying to delete Apr files
[root#dasari9 /]# bash -x log.sh
+ Jan=Dec
+ Feb=Jan
+ Mar=Feb
+ Apr=Mar
+ May=Apr
+ Jun=May
+ Jul=Jun
+ Aug=Jul
+ Sep=Aug
+ Oct=Sep
+ Nov=Oct
+ Dev=Nov
+ DIR=/logDir
+ cd /logDir
++ pwd
+ PWD=/logDir
+ '[' /logDir == /logDir ']'
++ date
++ awk '{print $2}'
+ cmd=Apr
++ ls -ltr
++ grep '$Apr'
++ awk '{print $9}'
+ dat=
+ rm -rf
It seems like you're looking for an indirect variable reference. Your $cmd variable points to the variable $Apr and you want to use the value of $Apr.
Here's how you can do this (just the relevant lines):
cmd=$(date | awk '{print $2}')
eval month=\$$cmd
dat=$(ls -ltr | grep $month | awk '{print $9}')
The eval command resolves the indirect reference created by \$$cmd.
More details here: http://www.tldp.org/LDP/abs/html/ivr.html
Perl is excellent language to store command output to variable
As I know bash isn’t support that
for example
my $value = qx(ls -ltr);
print $value;
it will print: ( example )
-r-xr-xr-x 1 root root 761 May 30 2014 ASon.conf
-r-xr-xr-x 1 root root 699 May 30 2014 ascpl
drwxr-xr-x 2 root root 4096 Feb 24 13:22 da
drwx------ 2 root root 4096 Feb 25 08:08 vm-root
drwxr-x--- 2 root root 4096 Feb 25 08:10 hspeoot
-rw-r--r-- 1 root root 2451 Feb 25 16:12 gry.txt
-rw-r--r-- 1 root root 3112 Mar 1 09:49 new.xml
-rw-r--r-- 1 root root 44893 Mar 1 12:13 SMports.xml
-rwxr-xr-x 1 root root 101 Mar 2 09:56 test
-rwxr-xr-x 1 root root 461340404 Mar 2 10:20 audin.log
the problem is that I write my code with bash
and I want to use the Perl add value in my bash script
so is it possible to combine the following line in my bash script?
my $value = qx(ls -ltr);
in way that when I print the value variable it will print the ls -ltr output
You don't need perl for this, your shell can handle it:
value=$(ls -ltr)
echo "$value"
The quotes when you echo are important.
In Perl:
$var = `shell command`;
$var = qx( shell command );
In sh:
var=`shell command`
var=$( shell command )
I have a files in a folder like this :
-rwxrwxrwx 1 www-data www-data 25088 Nov 6 2013 108400344_2223_abstraksi.doc
-rwxrwxrwx 1 www-data www-data 15119 Nov 6 2013 108400344_2223_abstraksi.docx
-rwxrwxrwx 1 www-data www-data 146532 Nov 6 2013 108400344_2223_abstraksi.pdf
-rwxrwxrwx 1 www-data www-data 145408 Nov 6 2013 108400344_2223_bab1.doc
-rwxrwxrwx 1 www-data www-data 75399 Nov 6 2013 108400344_2223_bab1.docx
-rwxrwxrwx 1 www-data www-data 193581 Nov 6 2013 108400344_2223_bab1.pdf
-rwxrwxrwx 1 www-data www-data 156672 Nov 6 2013 108400344_2223_bab2.doc
-rwxrwxrwx 1 www-data www-data 101341 Nov 6 2013 108400344_2223_bab2.docx
-rwxrwxrwx 1 www-data www-data 316476 Nov 6 2013 108400344_2223_bab2.pdf
-rwxrwxrwx 1 www-data www-data 952320 Nov 6 2013 108400344_2223_bab3.doc
-rwxrwxrwx 1 www-data www-data 89826 Nov 6 2013 108400344_2223_bab3.docx
-rwxrwxrwx 1 www-data www-data 399203 Nov 6 2013 108400344_2223_bab3.pdf
And then i want to change "108400344_2223_" to be "14.04.329" in the same time. I try almost all tutorial but it fail..so how to do this in linux ubuntu server 12.04?
Thanks
Given your files in some directory 'e':
$ ls -1 e/
108400344_2223_abstraksi.doc
108400344_2223_abstraksi.docx
108400344_2223_abstraksi.pdf
108400344_2223_bab1.doc
108400344_2223_bab1.docx
108400344_2223_bab1.pdf
108400344_2223_bab2.doc
108400344_2223_bab2.docx
108400344_2223_bab2.pdf
108400344_2223_bab3.doc
108400344_2223_bab3.docx
108400344_2223_bab3.pdf
You can easily use string substitution to rename all files from 108400344_2223_file to 14.04.329file
$ for i in e/*; do mv "$i" ${i//108400344_2223_/14.04.329}; done
confirm:
$ ls -11 e
14.04.329abstraksi.doc
14.04.329abstraksi.docx
14.04.329abstraksi.pdf
14.04.329bab1.doc
14.04.329bab1.docx
14.04.329bab1.pdf
14.04.329bab2.doc
14.04.329bab2.docx
14.04.329bab2.pdf
14.04.329bab3.doc
14.04.329bab3.docx
14.04.329bab3.pdf
Personally, I would add an underscore between the date and file:
$ for i in e/*; do mv "$i" ${i//108400344_2223/14.04.329}; done
Giving:
14.04.329_abstraksi.doc
14.04.329_abstraksi.docx
...
Hope that helps.
There are many ways to do this.
Since Ubuntu comes with the perl rename program, you could simply do
rename 's/108400344_2223_/14.04.329_/' *
Shell
for f in *; do mv "$f" "${f/108400344_2223_/14.04.329_}"; done
If the files can be in multiple sub directories, use find:
find . -name '108400344_2223_*' -exec rename 's/108400344_2223_/14.04.329_/' {} +
I hope this will be helpfull
for k in `ls -la | awk '{print $9}'`; do mv $k 14.04.329`ls -la $k | awk -F _ '{print $3}'`; done
output is like this:
-rw-r--r-- 1 root root 0 Sep 23 09:46 14.04.329abstraksi.doc
-rw-r--r-- 1 root root 0 Sep 23 09:46 14.04.329abstraksi.docx
-rw-r--r-- 1 root root 0 Sep 23 09:46 14.04.329abstraksi.pdf
-rw-r--r-- 1 root root 0 Sep 23 09:46 14.04.329bab1.doc
-rw-r--r-- 1 root root 0 Sep 23 09:46 14.04.329bab1.docx
-rw-r--r-- 1 root root 0 Sep 23 09:46 14.04.329bab1.pdf
-rw-r--r-- 1 root root 0 Sep 23 09:46 14.04.329bab2.doc
Basically I'm trying to compare the output of two files(one from PC which converts .cpio file to the layout format using standard tools, and another from embedded device using busybox tools), both of them produces the file system file/directory layout in 'ls -l' format. But the problem i got now is the output from embedded device prints the directory with some size info, which is not present .cpio.
Hence i have decided to replace directory content lines with 0 bytes size for the size column.
output from device :-
drwxrwxr-x 2 root root 5512 Aug 22 2013 bin
lrwxrwxrwx 1 root root 7 Aug 22 2013 bin/addgroup -> busybox
lrwxrwxrwx 1 root root 7 Aug 22 2013 bin/adduser -> busybox
lrwxrwxrwx 1 root root 7 Aug 22 2013 bin/ash -> busybox
output from PC :-
drwxrwxr-x 2 root root 0 Aug 22 09:32 bin
lrwxrwxrwx 1 root root 7 Aug 22 09:24 bin/addgroup -> busybox
lrwxrwxrwx 1 root root 7 Aug 22 09:24 bin/adduser -> busybox
lrwxrwxrwx 1 root root 7 Aug 22 09:24 bin/ash -> busybox
By comparing the output i have two issues to fix.
1) directory size is not shown correctly, i want to use awk/sed to replace this with '0' on device side.
2) similarly '09:32' time needs to be replaced with '2013', if i know how to do the first i will do the second by myself.
Please share you ideas to fix this.
$ cat foo.input
drwxrwxr-x 2 root root 5512 Aug 22 2013 bin
lrwxrwxrwx 1 root root 7 Aug 22 2013 bin/addgroup -> busybox
lrwxrwxrwx 1 root root 7 Aug 22 2013 bin/adduser -> busybox
lrwxrwxrwx 1 root root 7 Aug 22 2013 bin/ash -> busybox
$ cat foo2.input
drwxrwxr-x 2 root root 0 Aug 22 09:32 bin
lrwxrwxrwx 1 root root 7 Aug 22 09:24 bin/addgroup -> busybox
lrwxrwxrwx 1 root root 7 Aug 22 09:24 bin/adduser -> busybox
lrwxrwxrwx 1 root root 12345 Aug 22 09:24 bin/ash -> busybox
$ diff <(awk '/^d/{$5=0}{$6=$7=$8=""}1' foo.input) <(awk '/^d/{$5=0}{$6=$7=$8=""}1' foo2.input)
4c4
< lrwxrwxrwx 1 root root 7 bin/ash -> busybox
---
> lrwxrwxrwx 1 root root 12345 bin/ash -> busybox
/^d/{$5=0} sets field (column) 5 to 0 if the line matches ^d (= starts with d = directory)
{$6=$7=$8=""} deletes fields 6, 7, 8 for all lines since you want to ignore the date in your output
print results and diff their output
Preserving spacing:
$ awk '
BEGIN{ preRE="^([^[:space:]]+[[:space:]]+){4}" }
/^d/{
match($0,preRE)
preLgth=RLENGTH
match($0,preRE "[^[:space:]]+")
strLgth=RLENGTH-preLgth
$0 = substr($0,1,preLgth) sprintf("%*s",strLgth,0) substr($0,preLgth+strLgth+1)
}
1
' file
drwxrwxr-x 2 root root 0 Aug 22 2013 bin
lrwxrwxrwx 1 root root 7 Aug 22 2013 bin/addgroup -> busybox
lrwxrwxrwx 1 root root 7 Aug 22 2013 bin/adduser -> busybox
lrwxrwxrwx 1 root root 7 Aug 22 2013 bin/ash -> busybox